From 175e73e5659169d8ea79af2f76b5443f4b08800c Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 2 Nov 2023 14:05:14 +0100 Subject: [PATCH 1/9] fix(clientCredit): refs #6150 se arreglan los inserts en clientCredit --- db/changes/234601/00-clientAfterUpdate.sql | 77 +++++++++++++++++++ modules/client/back/models/client-config.json | 3 + modules/client/back/models/client.js | 20 ++--- .../client/back/models/specs/client.spec.js | 4 +- modules/ticket/front/summary/index.html | 2 +- modules/worker/back/methods/worker/new.js | 13 +++- 6 files changed, 102 insertions(+), 17 deletions(-) create mode 100644 db/changes/234601/00-clientAfterUpdate.sql diff --git a/db/changes/234601/00-clientAfterUpdate.sql b/db/changes/234601/00-clientAfterUpdate.sql new file mode 100644 index 000000000..4ae594deb --- /dev/null +++ b/db/changes/234601/00-clientAfterUpdate.sql @@ -0,0 +1,77 @@ +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 ; diff --git a/modules/client/back/models/client-config.json b/modules/client/back/models/client-config.json index 90d47333d..6c5eae7d7 100644 --- a/modules/client/back/models/client-config.json +++ b/modules/client/back/models/client-config.json @@ -17,6 +17,9 @@ }, "maxCreditRows": { "type": "number" + }, + "defaultCredit": { + "type": "number" } } } \ No newline at end of file diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index e16e884cc..72b702779 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -450,14 +450,14 @@ module.exports = Self => { if (lastCredit && lastCredit.amount == 0) { const zeroCreditEditor = - await models.ACL.checkAccessAcl(accessToken, 'Client', 'zeroCreditEditor', 'WRITE'); + await models.ACL.checkAccessAcl(accessToken, 'Client', 'zeroCreditEditor', 'WRITE'); const lastCreditIsNotEditable = - await models.ACL.checkAccessAcl( - {req: {accessToken: {userId: lastCredit.workerFk}}}, - 'Client', - 'zeroCreditEditor', - 'WRITE' - ); + await models.ACL.checkAccessAcl( + {req: {accessToken: {userId: lastCredit.workerFk}}}, + 'Client', + 'zeroCreditEditor', + 'WRITE' + ); if (lastCreditIsNotEditable && !zeroCreditEditor) throw new UserError(`You can't change the credit set to zero from a financialBoss`); @@ -483,12 +483,6 @@ module.exports = Self => { if (userRequiredRoles <= 0) throw new UserError(`You don't have enough privileges to set this credit amount`); } - - await models.ClientCredit.create({ - amount: changes.credit, - clientFk: finalState.id, - workerFk: userId - }, ctx.options); }; Self.changeCreditManagement = async function changeCreditManagement(ctx, finalState, changes) { diff --git a/modules/client/back/models/specs/client.spec.js b/modules/client/back/models/specs/client.spec.js index 201d14bb4..bf134fbf9 100644 --- a/modules/client/back/models/specs/client.spec.js +++ b/modules/client/back/models/specs/client.spec.js @@ -62,13 +62,13 @@ describe('Client Model', () => { const options = {transaction: tx}; const ctx = {options}; - // Set credit to zero by a financialBoss const financialBoss = await models.VnUser.findOne({ where: {name: 'financialBoss'} }, options); ctx.options.accessToken = {userId: financialBoss.id}; - await models.Client.changeCredit(ctx, instance, {credit: 0}); + const testClient = await models.Client.findById(instance.id, options); + await testClient.updateAttributes({credit: 0}, ctx.options); const salesAssistant = await models.VnUser.findOne({ where: {name: 'salesAssistant'} diff --git a/modules/ticket/front/summary/index.html b/modules/ticket/front/summary/index.html index 3c60352a7..4cf7ed11d 100644 --- a/modules/ticket/front/summary/index.html +++ b/modules/ticket/front/summary/index.html @@ -212,7 +212,7 @@ {{::sale.quantity}}
- {{::sale.item.name}} + {{::sale.concept}}

{{::sale.item.subName}}

diff --git a/modules/worker/back/methods/worker/new.js b/modules/worker/back/methods/worker/new.js index 5316daf01..c9cebda7a 100644 --- a/modules/worker/back/methods/worker/new.js +++ b/modules/worker/back/methods/worker/new.js @@ -119,7 +119,8 @@ module.exports = Self => { Self.new = async(ctx, options) => { const models = Self.app.models; - const myOptions = {userId: ctx.req.accessToken.userId}; + const {userId} = ctx.req.accessToken; + const myOptions = {userId}; const args = ctx.args; let tx; @@ -188,6 +189,16 @@ module.exports = Self => { myOptions ); + const {defaultCredit} = await models.ClientConfig.findOne(myOptions); + + await models.ClientCredit.create( + { + clientFk: user.id, + amount: defaultCredit, + workerFk: userId + }, myOptions + ); + const address = await models.Address.create( { clientFk: user.id, From a75565f2ce3e549355ee9601958acec07f9697a1 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 6 Nov 2023 14:23:36 +0100 Subject: [PATCH 2/9] feat(client.create): refs #6150 clientCredit update fix --- db/changes/234601/00-clientAfterUpdate.sql | 48 +++++++++++++++++++++- db/dump/fixtures.sql | 3 +- modules/worker/back/methods/worker/new.js | 10 ----- 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/db/changes/234601/00-clientAfterUpdate.sql b/db/changes/234601/00-clientAfterUpdate.sql index 4ae594deb..49854ebcd 100644 --- a/db/changes/234601/00-clientAfterUpdate.sql +++ b/db/changes/234601/00-clientAfterUpdate.sql @@ -1,3 +1,7 @@ +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` @@ -72,6 +76,48 @@ BEGIN 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`.`ticket_afterInsert` + AFTER INSERT ON `ticket` + FOR EACH ROW +BEGIN + DECLARE vClientType VARCHAR(255); + DECLARE vStateCode VARCHAR(255); + DECLARE vTransferorFirstShipped DATE; + + IF NEW.credit NOT NULL AND NEW.credit <> 0 THEN + INSERT INTO clientCredit + SET clientFk = NEW.id, + workerFk = NEW.editorFk, + amount = NEW.credit; + END IF; + + -- 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/dump/fixtures.sql b/db/dump/fixtures.sql index faf58fd78..1dd8a7bd8 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -491,7 +491,8 @@ INSERT INTO `vn`.`clientCreditLimit`(`id`, `maxAmount`, `roleFk`) VALUES (1, 9999999, 20), (2, 10000, 21), - (3, 600, 13); + (3, 600, 13), + (4, 300, 37); INSERT INTO `vn`.`clientObservation`(`id`, `clientFk`, `workerFk`, `text`, `created`) VALUES diff --git a/modules/worker/back/methods/worker/new.js b/modules/worker/back/methods/worker/new.js index c9cebda7a..6610e6919 100644 --- a/modules/worker/back/methods/worker/new.js +++ b/modules/worker/back/methods/worker/new.js @@ -189,16 +189,6 @@ module.exports = Self => { myOptions ); - const {defaultCredit} = await models.ClientConfig.findOne(myOptions); - - await models.ClientCredit.create( - { - clientFk: user.id, - amount: defaultCredit, - workerFk: userId - }, myOptions - ); - const address = await models.Address.create( { clientFk: user.id, From b442c9f5ed2a5b09389c3be63af8bd8261494e0a Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 6 Nov 2023 14:54:56 +0100 Subject: [PATCH 3/9] fix: refs #6150 ticket to client trigger --- db/changes/234601/00-clientAfterUpdate.sql | 38 +++++++--------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/db/changes/234601/00-clientAfterUpdate.sql b/db/changes/234601/00-clientAfterUpdate.sql index 49854ebcd..90ff5d52a 100644 --- a/db/changes/234601/00-clientAfterUpdate.sql +++ b/db/changes/234601/00-clientAfterUpdate.sql @@ -80,44 +80,30 @@ END$$ DELIMITER ; DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticket_afterInsert` - AFTER INSERT ON `ticket` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_beforeInsert` + BEFORE INSERT ON `client` FOR EACH ROW BEGIN - DECLARE vClientType VARCHAR(255); - DECLARE vStateCode VARCHAR(255); - DECLARE vTransferorFirstShipped DATE; - - IF NEW.credit NOT NULL AND NEW.credit <> 0 THEN + IF NEW.credit NOT NULL AND NEW.credit THEN INSERT INTO clientCredit SET clientFk = NEW.id, workerFk = NEW.editorFk, amount = NEW.credit; END IF; - -- Borrar cuando se cambie el insert ticket en la APP móvil + SET NEW.editorFk = account.myUser_getId(); - SELECT typeFk INTO vClientType - FROM vn.`client` WHERE id = NEW.clientFk; - - IF vClientType = 'loses' THEN - SET vStateCode = 'DELIVERED'; - ELSE - SET vStateCode = 'FREE'; + IF (NEW.phone <> '') THEN + CALL pbx.phone_isValid(NEW.phone); 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(); + 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 ; From 1c6618d49432d07ff59ec49b7676bd7d78e302d9 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 6 Nov 2023 14:56:48 +0100 Subject: [PATCH 4/9] fix(new): refs #6150 revert chabges in worker new method --- modules/worker/back/methods/worker/new.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/worker/back/methods/worker/new.js b/modules/worker/back/methods/worker/new.js index 6610e6919..5316daf01 100644 --- a/modules/worker/back/methods/worker/new.js +++ b/modules/worker/back/methods/worker/new.js @@ -119,8 +119,7 @@ module.exports = Self => { Self.new = async(ctx, options) => { const models = Self.app.models; - const {userId} = ctx.req.accessToken; - const myOptions = {userId}; + const myOptions = {userId: ctx.req.accessToken.userId}; const args = ctx.args; let tx; From 0818efaa9936c8eb7244c5df83887852cb97cd2b Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 6 Nov 2023 14:58:39 +0100 Subject: [PATCH 5/9] fix(fixtures): refs #6150 clientCredit --- db/dump/fixtures.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index d0afa8d81..d70279e7d 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -491,8 +491,7 @@ INSERT INTO `vn`.`clientCreditLimit`(`id`, `maxAmount`, `roleFk`) VALUES (1, 9999999, 20), (2, 10000, 21), - (3, 600, 13), - (4, 300, 37); + (3, 600, 13); INSERT INTO `vn`.`clientObservation`(`id`, `clientFk`, `workerFk`, `text`, `created`) VALUES From d30c4e446379ae2adbb2112cb84ae205ad252b3a Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 7 Nov 2023 16:13:21 +0100 Subject: [PATCH 6/9] refs #5652 feat:addressShortage --- db/changes/234601/00-addressShortage.sql | 97 +++++++++++++++++++ modules/client/back/model-config.json | 3 + .../client/back/models/addressShortage.json | 22 +++++ 3 files changed, 122 insertions(+) create mode 100644 db/changes/234601/00-addressShortage.sql create mode 100644 modules/client/back/models/addressShortage.json diff --git a/db/changes/234601/00-addressShortage.sql b/db/changes/234601/00-addressShortage.sql new file mode 100644 index 000000000..dd8ef8e4b --- /dev/null +++ b/db/changes/234601/00-addressShortage.sql @@ -0,0 +1,97 @@ + +-- Place your SQL code here + +ALTER TABLE `vn`.`productionConfig` ADD shortageAddressFk int(11) COMMENT 'Address 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 CASCADE 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, + vQuantity INT, + vAddressFk INT) +BEGIN +/** + * Procedimiento para dar dar de baja/alta un item, si vAddressFk es NULL se entiende que se da de alta y se toma el addressFk de la configuración + * + * @param vItemFk Identificador del ítem + * @param vWarehouseFk id del warehouse + * @param vQuantity a dar de alta/baja + * @param vAddressFk id address + */ + DECLARE vTicketFk INT; + DECLARE vClientFk INT; + DECLARE vCompanyVnlFk INT; + DECLARE vCalc INT; + DECLARE vAddressShortage INT; + + SELECT barcodeToItem(vItemFk) INTO vItemFk; + + SELECT DEFAULT(companyFk) INTO vCompanyVnlFk + FROM vn.ticket LIMIT 1; + + IF vAddressFk IS NULL THEN + SELECT pc.shortageAddressFk FROM productionConfig pc INTO vAddressShortage; + ELSE + SET vAddressShortage = vAddressFk; + END IF; + + SELECT a.clientFk INTO vClientFk + FROM address a + WHERE a.id = vAddressFk; + + SELECT t.id INTO vTicketFk + FROM ticket t + JOIN address a ON a.id = t.addressFk + JOIN ticketState ts ON ts.ticketFk = t.id + WHERE t.warehouseFk = vWarehouseFk + AND a.id = vAddressShortage + AND DATE(t.shipped) = util.VN_CURDATE() + AND ts.code = 'DELIVERED' + LIMIT 1; + + CALL cache.visible_refresh(vCalc, TRUE, vWarehouseFk); + + IF vTicketFk IS NULL THEN + CALL ticket_add( + vClientFk, + util.VN_CURDATE(), + vWarehouseFk, + vCompanyVnlFk, + vAddressFk, + NULL, + NULL, + util.VN_CURDATE(), + account.myUser_getId(), + FALSE, + vTicketFk); + END IF; + + INSERT INTO sale(ticketFk, itemFk, concept, quantity) + SELECT vTicketFk, + vItemFk, + CONCAT(longName,' ', worker_getCode(), ' ', LEFT(CAST(util.VN_NOW() AS TIME),5)), + vQuantity + FROM item + WHERE id = vItemFk; + + UPDATE cache.visible + SET visible = visible - vQuantity + WHERE calc_id = vCalc + AND item_id = vItemFk; +END$$ +DELIMITER ; diff --git a/modules/client/back/model-config.json b/modules/client/back/model-config.json index 296b5e6a7..0cc5df9a2 100644 --- a/modules/client/back/model-config.json +++ b/modules/client/back/model-config.json @@ -5,6 +5,9 @@ "AddressObservation": { "dataSource": "vn" }, + "AddressShortage": { + "dataSource": "vn" + }, "BankEntity": { "dataSource": "vn" }, diff --git a/modules/client/back/models/addressShortage.json b/modules/client/back/models/addressShortage.json new file mode 100644 index 000000000..1ae8d986c --- /dev/null +++ b/modules/client/back/models/addressShortage.json @@ -0,0 +1,22 @@ +{ + "name": "AddressShortage", + "base": "VnModel", + "options": { + "mysql": { + "table": "addressShortage" + } + }, + "properties": { + "addressFk": { + "type": "number", + "id": true + } + }, + "relations": { + "address": { + "type": "belongsTo", + "model": "Address", + "foreignKey": "addressFk" + } + } +} \ No newline at end of file From 5751065e6a0f14d27314ec1cad944b52ddc57d83 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 8 Nov 2023 11:50:04 +0100 Subject: [PATCH 7/9] refs #5652 feat:addressShortage --- db/changes/234601/00-addressShortage.sql | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/db/changes/234601/00-addressShortage.sql b/db/changes/234601/00-addressShortage.sql index dd8ef8e4b..57c07d480 100644 --- a/db/changes/234601/00-addressShortage.sql +++ b/db/changes/234601/00-addressShortage.sql @@ -1,8 +1,8 @@ -- Place your SQL code here -ALTER TABLE `vn`.`productionConfig` ADD shortageAddressFk int(11) COMMENT 'Address 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 CASCADE ON UPDATE CASCADE; +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'; @@ -35,17 +35,18 @@ BEGIN */ DECLARE vTicketFk INT; DECLARE vClientFk INT; - DECLARE vCompanyVnlFk INT; + DECLARE vDefaultCompanyFk INT; DECLARE vCalc INT; DECLARE vAddressShortage INT; SELECT barcodeToItem(vItemFk) INTO vItemFk; - SELECT DEFAULT(companyFk) INTO vCompanyVnlFk + SELECT DEFAULT(companyFk) INTO vDefaultCompanyFk FROM vn.ticket LIMIT 1; IF vAddressFk IS NULL THEN - SELECT pc.shortageAddressFk FROM productionConfig pc INTO vAddressShortage; + SELECT pc.shortageAddressFk INTO vAddressShortage + FROM productionConfig pc ; ELSE SET vAddressShortage = vAddressFk; END IF; @@ -71,7 +72,7 @@ BEGIN vClientFk, util.VN_CURDATE(), vWarehouseFk, - vCompanyVnlFk, + vDefaultCompanyFk, vAddressFk, NULL, NULL, From 4258015c07336fbb7182d8e86e8b5ebc2809a802 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 9 Nov 2023 08:04:38 +0100 Subject: [PATCH 8/9] refs #5870 feat:fixModel --- modules/worker/back/models/operator.json | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/worker/back/models/operator.json b/modules/worker/back/models/operator.json index 2417078e1..6da3945fc 100644 --- a/modules/worker/back/models/operator.json +++ b/modules/worker/back/models/operator.json @@ -33,6 +33,16 @@ "type": "belongsTo", "model": "Sector", "foreignKey": "sectorFk" + }, + "train": { + "type": "belongsTo", + "model": "Train", + "foreignKey": "trainFk" + }, + "printer": { + "type": "belongsTo", + "model": "Printer", + "foreignKey": "labelerFk" } } } From 973eff4520c526bebad43daad9b4e97dd795792b Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 9 Nov 2023 09:05:56 +0100 Subject: [PATCH 9/9] refs #6415 fix. sql files --- db/changes/234201/00-packagingFkviews.sql | 2 ++ .../234601/00-ACLticketTrackingState.sql | 8 ----- .../00-claimViewerAcl.sql} | 10 +++--- db/changes/234601/00-claimViewweAcl.sql | 31 ----------------- db/changes/234601/00-clientAfterUpdate.sql | 20 ++--------- db/dump/fixtures.sql | 34 +++++++++---------- 6 files changed, 27 insertions(+), 78 deletions(-) rename db/changes/{233601/00-createClaimReader.sql => 234601/00-claimViewerAcl.sql} (86%) delete mode 100644 db/changes/234601/00-claimViewweAcl.sql diff --git a/db/changes/234201/00-packagingFkviews.sql b/db/changes/234201/00-packagingFkviews.sql index abc7dc004..49d41c26c 100644 --- a/db/changes/234201/00-packagingFkviews.sql +++ b/db/changes/234201/00-packagingFkviews.sql @@ -1,3 +1,5 @@ +CREATE SCHEMA IF NOT EXISTS `vn2008`; + CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vn`.`awbVolume` diff --git a/db/changes/234601/00-ACLticketTrackingState.sql b/db/changes/234601/00-ACLticketTrackingState.sql index 0f7bd4f44..ca6dce0c9 100644 --- a/db/changes/234601/00-ACLticketTrackingState.sql +++ b/db/changes/234601/00-ACLticketTrackingState.sql @@ -2,11 +2,3 @@ UPDATE `salix`.`ACL` SET `property` = 'state', `model` = 'Ticket' WHERE `property` = 'changeState'; - -REVOKE INSERT, UPDATE, DELETE ON `vn`.`ticketTracking` FROM 'productionboss'@; -REVOKE INSERT, UPDATE, DELETE ON `vn`.`ticketTracking` FROM 'productionAssi'@; -REVOKE INSERT, UPDATE, DELETE ON `vn`.`ticketTracking` FROM 'hr'@; -REVOKE INSERT, UPDATE, DELETE ON `vn`.`ticketTracking` FROM 'salesPerson'@; -REVOKE INSERT, UPDATE, DELETE ON `vn`.`ticketTracking` FROM 'deliveryPerson'@; -REVOKE INSERT, UPDATE, DELETE ON `vn`.`ticketTracking` FROM 'employee'@; -REVOKE EXECUTE ON `vn`.`ticket_setState` FROM 'employee'@; diff --git a/db/changes/233601/00-createClaimReader.sql b/db/changes/234601/00-claimViewerAcl.sql similarity index 86% rename from db/changes/233601/00-createClaimReader.sql rename to db/changes/234601/00-claimViewerAcl.sql index e913c0ed9..17d8d4ce0 100644 --- a/db/changes/233601/00-createClaimReader.sql +++ b/db/changes/234601/00-claimViewerAcl.sql @@ -21,11 +21,11 @@ DELETE FROM `salix`.`ACL` 'getSummary' ); -INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalid`) +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`) +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`) +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'); \ No newline at end of file +INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) + VALUES ('Claim','getSummary','READ','ALLOW','ROLE','claimViewer'); diff --git a/db/changes/234601/00-claimViewweAcl.sql b/db/changes/234601/00-claimViewweAcl.sql deleted file mode 100644 index e913c0ed9..000000000 --- a/db/changes/234601/00-claimViewweAcl.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'); \ No newline at end of file diff --git a/db/changes/234601/00-clientAfterUpdate.sql b/db/changes/234601/00-clientAfterUpdate.sql index 90ff5d52a..c6483813f 100644 --- a/db/changes/234601/00-clientAfterUpdate.sql +++ b/db/changes/234601/00-clientAfterUpdate.sql @@ -80,30 +80,16 @@ END$$ DELIMITER ; DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_beforeInsert` - BEFORE INSERT ON `client` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_AfterInsert` + AFTER INSERT ON `client` FOR EACH ROW BEGIN - IF NEW.credit NOT NULL AND NEW.credit THEN + 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; - - 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/dump/fixtures.sql b/db/dump/fixtures.sql index d70279e7d..ae47a1eef 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -470,22 +470,22 @@ CREATE TEMPORARY TABLE tmp.address WHERE `defaultAddressFk` IS NULL; DROP TEMPORARY TABLE tmp.address; -INSERT INTO `vn`.`clientCredit`(`id`, `clientFk`, `workerFk`, `amount`, `created`) +INSERT INTO `vn`.`clientCredit`(`clientFk`, `workerFk`, `amount`, `created`) VALUES - (1 , 1101, 5, 300, DATE_ADD(util.VN_CURDATE(), INTERVAL -11 MONTH)), - (2 , 1101, 5, 900, DATE_ADD(util.VN_CURDATE(), INTERVAL -10 MONTH)), - (3 , 1101, 5, 800, DATE_ADD(util.VN_CURDATE(), INTERVAL -9 MONTH)), - (4 , 1101, 5, 700, DATE_ADD(util.VN_CURDATE(), INTERVAL -8 MONTH)), - (5 , 1101, 5, 600, DATE_ADD(util.VN_CURDATE(), INTERVAL -7 MONTH)), - (6 , 1101, 5, 500, DATE_ADD(util.VN_CURDATE(), INTERVAL -6 MONTH)), - (7 , 1101, 5, 400, DATE_ADD(util.VN_CURDATE(), INTERVAL -5 MONTH)), - (8 , 1101, 9, 300, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH)), - (9 , 1101, 9, 200, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH)), - (10, 1101, 9, 100, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH)), - (11, 1101, 9, 50 , DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), - (12, 1102, 9, 800, util.VN_CURDATE()), - (14, 1104, 9, 90 , util.VN_CURDATE()), - (15, 1105, 9, 90 , util.VN_CURDATE()); + (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`.`clientCreditLimit`(`id`, `maxAmount`, `roleFk`) VALUES @@ -2758,7 +2758,7 @@ 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`) +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); @@ -2986,4 +2986,4 @@ INSERT INTO `vn`.`invoiceCorrectionType` (`id`, `description`) VALUES (1, 'Error in VAT calculation'), (2, 'Error in sales details'), - (3, 'Error in customer data'); \ No newline at end of file + (3, 'Error in customer data');