From 98fb3c1a67094943bc4b9f3b6e8717de9ad50c8b Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 30 Mar 2022 08:09:52 +0200 Subject: [PATCH 1/2] refactor(client_updatePorfolio): included backTest --- .../client/back/methods/client/specs/updatePortfolio.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/client/back/methods/client/specs/updatePortfolio.spec.js b/modules/client/back/methods/client/specs/updatePortfolio.spec.js index 7983bb2ff..2554daf3d 100644 --- a/modules/client/back/methods/client/specs/updatePortfolio.spec.js +++ b/modules/client/back/methods/client/specs/updatePortfolio.spec.js @@ -26,8 +26,8 @@ describe('Client updatePortfolio', () => { throw e; } }); - // 3742 first have to migrate vn2008.Clientes_cedidos to vn - xit('should keep the same portfolioWeight when a salesperson is unassigned of a client', async() => { + + it('should keep the same portfolioWeight when a salesperson is unassigned of a client', async() => { const salesPersonId = 19; const tx = await models.Client.beginTransaction({}); From e29f820e607cff608333470b7f43e5ab22bc2f77 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 30 Mar 2022 08:56:35 +0200 Subject: [PATCH 2/2] feat(ticket_line): new table ticketRefund and update proc ticket_doRefund --- db/changes/10440-fallas/00-ticketRefund.sql | 149 ++++++++++++++++++++ db/dump/fixtures.sql | 12 -- loopback/locale/es.json | 3 +- 3 files changed, 151 insertions(+), 13 deletions(-) create mode 100644 db/changes/10440-fallas/00-ticketRefund.sql diff --git a/db/changes/10440-fallas/00-ticketRefund.sql b/db/changes/10440-fallas/00-ticketRefund.sql new file mode 100644 index 000000000..66de21e91 --- /dev/null +++ b/db/changes/10440-fallas/00-ticketRefund.sql @@ -0,0 +1,149 @@ +DROP PROCEDURE IF EXISTS `vn`.`ticket_doRefund`; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_doRefund`(IN vOriginTicket INT, OUT vNewTicket INT) +BEGIN + + DECLARE vDone BIT DEFAULT 0; + DECLARE vCustomer MEDIUMINT; + DECLARE vWarehouse TINYINT; + DECLARE vCompany MEDIUMINT; + DECLARE vAddress MEDIUMINT; + DECLARE vRefundAgencyMode INT; + DECLARE vItemFk INT; + DECLARE vQuantity DECIMAL (10,2); + DECLARE vConcept VARCHAR(50); + DECLARE vPrice DECIMAL (10,2); + DECLARE vDiscount TINYINT; + DECLARE vSaleNew INT; + DECLARE vSaleMain INT; + DECLARE vZoneFk INT; + + DECLARE vRsMainTicket CURSOR FOR + SELECT * + FROM tmp.sale; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = 1; + + SELECT id INTO vRefundAgencyMode + FROM agencyMode WHERE `name` = 'ABONO'; + + SELECT clientFk, warehouseFk, companyFk, addressFk + INTO vCustomer, vWarehouse, vCompany, vAddress + FROM ticket + WHERE id = vOriginTicket; + + SELECT id INTO vZoneFk + FROM zone WHERE agencyModeFk = vRefundAgencyMode + LIMIT 1; + + INSERT INTO vn.ticket ( + clientFk, + shipped, + addressFk, + agencyModeFk, + nickname, + warehouseFk, + companyFk, + landed, + zoneFk + ) + SELECT + vCustomer, + CURDATE(), + vAddress, + vRefundAgencyMode, + a.nickname, + vWarehouse, + vCompany, + CURDATE(), + vZoneFk + FROM address a + WHERE a.id = vAddress; + + SET vNewTicket = LAST_INSERT_ID(); + + SET vDone := 0; + OPEN vRsMainTicket ; + FETCH vRsMainTicket INTO vSaleMain, vItemFk, vQuantity, vConcept, vPrice, vDiscount; + + WHILE NOT vDone DO + + INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept, price, discount) + VALUES( vNewTicket, vItemFk, vQuantity, vConcept, vPrice, vDiscount ); + + SET vSaleNew = LAST_INSERT_ID(); + + INSERT INTO vn.saleComponent(saleFk,componentFk,`value`) + SELECT vSaleNew,componentFk,`value` + FROM vn.saleComponent + WHERE saleFk = vSaleMain; + + FETCH vRsMainTicket INTO vSaleMain, vItemFk, vQuantity, vConcept, vPrice, vDiscount; + + END WHILE; + CLOSE vRsMainTicket; + + INSERT INTO vn.ticketRefund(refundTicketFk, originalTicketFk) + VALUES(vNewTicket, vOriginTicket); + +END$$ +DELIMITER ; + +CREATE TABLE `vn`.`ticketRefund` ( + `id` INT auto_increment NULL, + `refundTicketFk` INT NOT NULL, + `originalTicketFk` INT NOT NULL, + CONSTRAINT `ticketRefund_PK` PRIMARY KEY (id) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8 +COLLATE=utf8_unicode_ci; + +ALTER TABLE `vn`.`ticketRefund` ADD CONSTRAINT `ticketRefund_FK` FOREIGN KEY (`refundTicketFk`) REFERENCES `vn`.`ticket`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE `vn`.`ticketRefund` ADD CONSTRAINT `ticketRefund_FK_1` FOREIGN KEY (`originalTicketFk`) REFERENCES `vn`.`ticket`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketRefund_beforeInsert` + BEFORE INSERT ON `ticketRefund` + FOR EACH ROW +BEGIN + DECLARE vAlreadyExists BOOLEAN DEFAULT FALSE; + + IF NEW.refundTicketFk = NEW.originalTicketFk THEN + CALL util.throw('Original ticket and refund ticket has same id'); + END IF; + + SELECT COUNT(*) INTO vAlreadyExists + FROM ticketRefund + WHERE refundTicketFk = NEW.originalTicketFk; + + IF vAlreadyExists > 0 THEN + CALL util.throw('This ticket is already a refund'); + END IF; +END$$ +DELIMITER ; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketRefund_beforeUpdate` + BEFORE UPDATE ON `ticketRefund` + FOR EACH ROW +BEGIN + DECLARE vAlreadyExists BOOLEAN DEFAULT FALSE; + + IF NEW.refundTicketFk = NEW.originalTicketFk THEN + CALL util.throw('Original ticket and refund ticket has same id'); + END IF; + + SELECT COUNT(*) INTO vAlreadyExists + FROM ticketRefund + WHERE refundTicketFk = NEW.originalTicketFk; + + IF vAlreadyExists > 0 THEN + CALL util.throw('This ticket is already a refund'); + END IF; +END$$ +DELIMITER ; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index aa03c39b5..e8302b1a2 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2477,18 +2477,6 @@ INSERT INTO `bs`.`defaulter` (`clientFk`, `amount`, `created`, `defaulterSinced` (1107, 500, CURDATE(), CURDATE()), (1109, 500, CURDATE(), CURDATE()); -UPDATE `vn`.`agency` - SET `supplierFk`=1 - WHERE `id`=1; - -UPDATE `vn`.`agency` - SET `supplierFk`=1 - WHERE `id`=2; - -UPDATE `vn`.`agency` - SET `supplierFk`=2 - WHERE `id`=3; - UPDATE `vn`.`route` SET `invoiceInFk`=1 WHERE `id`=1; diff --git a/loopback/locale/es.json b/loopback/locale/es.json index f7c0dad54..9310ae436 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -223,5 +223,6 @@ "The item is required": "El artículo es requerido", "The agency is already assigned to another autonomous": "La agencia ya está asignada a otro autónomo", "date in the future": "Fecha en el futuro", - "reference duplicated": "Referencia duplicada" + "reference duplicated": "Referencia duplicada", + "This ticket is already a refund": "Este ticket ya es un abono" } \ No newline at end of file