diff --git a/db/routines/util/procedures/connection_kill.sql b/db/routines/util/procedures/connection_kill.sql new file mode 100644 index 000000000..b38509d1b --- /dev/null +++ b/db/routines/util/procedures/connection_kill.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`connection_kill`( + vConnectionId BIGINT +) +BEGIN +/** + * Kill a connection + * + * @param vConnectionId + */ + KILL vConnectionId; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/collection_assign.sql b/db/routines/vn/procedures/collection_assign.sql index f6000e87d..196764c42 100644 --- a/db/routines/vn/procedures/collection_assign.sql +++ b/db/routines/vn/procedures/collection_assign.sql @@ -30,10 +30,9 @@ BEGIN -- Si hay colecciones sin terminar, sale del proceso CALL collection_get(vUserFk); - SELECT (pc.maxNotReadyCollections - COUNT(*)) <= 0 - INTO vHasTooMuchCollections - FROM tCollection - JOIN productionConfig pc; + SELECT (pc.maxNotReadyCollections - COUNT(*)) <= 0 INTO vHasTooMuchCollections + FROM productionConfig pc + LEFT JOIN tCollection ON TRUE; DROP TEMPORARY TABLE tCollection; @@ -47,7 +46,7 @@ BEGIN WHERE workerFk = vUserFk; SET vLockName = CONCAT_WS('/', - 'collection_assign', + vLockName, vWarehouseFk, vItemPackingTypeFk ); diff --git a/db/routines/vn/procedures/collection_new.sql b/db/routines/vn/procedures/collection_new.sql index f3767ddf3..8a1eff4a1 100644 --- a/db/routines/vn/procedures/collection_new.sql +++ b/db/routines/vn/procedures/collection_new.sql @@ -63,7 +63,8 @@ BEGIN o.numberOfWagons, o.trainFk, o.linesLimit, - o.volumeLimit + o.volumeLimit, + pc.collection_new_lockname INTO vMaxTickets, vHasUniqueCollectionTime, vWorkerCode, @@ -73,14 +74,15 @@ BEGIN vWagons, vTrainFk, vLinesLimit, - vVolumeLimit + vVolumeLimit, + vLockName 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; SET vLockName = CONCAT_WS('/', - 'collection_new', + vLockName, vWarehouseFk, vItemPackingTypeFk ); diff --git a/db/routines/vn/procedures/sale_replaceItem.sql b/db/routines/vn/procedures/sale_replaceItem.sql index 056397274..a4aefc088 100644 --- a/db/routines/vn/procedures/sale_replaceItem.sql +++ b/db/routines/vn/procedures/sale_replaceItem.sql @@ -79,6 +79,10 @@ BEGIN ORDER BY (vQuantity % `grouping`) ASC LIMIT 1; + IF vNewPrice IS NULL THEN + CALL util.throw('price retrieval failed'); + END IF; + IF vNewPrice > vOldPrice THEN SET vFinalPrice = vOldPrice; SET vOption = 'substitution'; @@ -90,7 +94,8 @@ BEGIN START TRANSACTION; UPDATE sale - SET quantity = quantity - vQuantity + SET originalQuantity = quantity - vQuantity, + quantity = quantity - vQuantity WHERE id = vSaleFk; INSERT INTO vn.sale(ticketFk, @@ -100,7 +105,8 @@ BEGIN price) SELECT vTicketFk, vNewItemFk, - CEIL(vQuantity / vRoundQuantity) * vRoundQuantity, CONCAT('+ ', i.name), + CEIL(vQuantity / vRoundQuantity) * vRoundQuantity, + CONCAT('+ ', i.name), vFinalPrice FROM vn.item i WHERE id = vNewItemFk; diff --git a/db/routines/vn/procedures/ticketRequest_Add.sql b/db/routines/vn/procedures/ticketRequest_Add.sql deleted file mode 100644 index 5ba347fef..000000000 --- a/db/routines/vn/procedures/ticketRequest_Add.sql +++ /dev/null @@ -1,19 +0,0 @@ -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/ticket_close.sql b/db/routines/vn/procedures/ticket_close.sql index 91e0979cd..47d748ddf 100644 --- a/db/routines/vn/procedures/ticket_close.sql +++ b/db/routines/vn/procedures/ticket_close.sql @@ -63,7 +63,7 @@ BEGIN INSERT INTO ticketPackaging (ticketFk, packagingFk, quantity) (SELECT vCurTicketFk, p.id, COUNT(*) FROM expedition e - JOIN packaging p ON p.itemFk = e.freightItemFk + JOIN packaging p ON p.id = e.packagingFk WHERE e.ticketFk = vCurTicketFk AND p.isPackageReturnable AND vWithPackage GROUP BY p.itemFk); diff --git a/db/routines/vn/triggers/ticketPackaging_beforeInsert.sql b/db/routines/vn/triggers/ticketPackaging_beforeInsert.sql index a58955e0d..f47a7ae35 100644 --- a/db/routines/vn/triggers/ticketPackaging_beforeInsert.sql +++ b/db/routines/vn/triggers/ticketPackaging_beforeInsert.sql @@ -4,7 +4,5 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketPackaging_befor 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/ticketRequest_beforeInsert.sql b/db/routines/vn/triggers/ticketRequest_beforeInsert.sql index d17459912..00e659abc 100644 --- a/db/routines/vn/triggers/ticketRequest_beforeInsert.sql +++ b/db/routines/vn/triggers/ticketRequest_beforeInsert.sql @@ -14,7 +14,7 @@ BEGIN END IF; IF NEW.attenderFk IS NULL THEN - SET NEW.attenderFk = (SELECT w.id FROM worker w WHERE w.code = NEW.buyerCode); + SET NEW.attenderFk = (SELECT defaultAttenderFk FROM ticketConfig LIMIT 1); END IF; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/ticketRequest_beforeUpdate.sql b/db/routines/vn/triggers/ticketRequest_beforeUpdate.sql index e5e9c307e..954df8ed3 100644 --- a/db/routines/vn/triggers/ticketRequest_beforeUpdate.sql +++ b/db/routines/vn/triggers/ticketRequest_beforeUpdate.sql @@ -12,9 +12,5 @@ BEGIN 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/versions/11002-limeCarnation/00-firstScript.sql b/db/versions/11002-limeCarnation/00-firstScript.sql new file mode 100644 index 000000000..b1a49a309 --- /dev/null +++ b/db/versions/11002-limeCarnation/00-firstScript.sql @@ -0,0 +1,7 @@ +-- Place your SQL code here +ALTER TABLE `vn`.`ticketRequest` + CHANGE IF EXISTS `buyerCode` `buyerCode__` varchar(3) NOT NULL COMMENT '@deprecated 2024-04-23 refs #6731 field not used'; + +ALTER TABLE `vn`.`ticketConfig` ADD COLUMN IF NOT EXISTS `defaultAttenderFk` int unsigned; + +ALTER TABLE vn.ticketConfig ADD CONSTRAINT ticketConfig_worker_FK FOREIGN KEY (defaultAttenderFk) REFERENCES vn.worker(id); diff --git a/db/versions/11016-pinkAralia/00-firstScript.sql b/db/versions/11016-pinkAralia/00-firstScript.sql new file mode 100644 index 000000000..de090013d --- /dev/null +++ b/db/versions/11016-pinkAralia/00-firstScript.sql @@ -0,0 +1,5 @@ +-- Place your SQL code here +ALTER TABLE vn.productionConfig ADD collectionNewLockname varchar(100) + DEFAULT 'collection_new' NOT NULL COMMENT 'Lockname value for proc vn.collection_new'; +ALTER TABLE vn.productionConfig ADD collectionAssignLockname varchar(100) + DEFAULT 'collection_assign' NULL COMMENT 'Lockname value for proc vn.collection_new'; diff --git a/db/versions/11018-crimsonBamboo/00-firstScript.sql b/db/versions/11018-crimsonBamboo/00-firstScript.sql new file mode 100644 index 000000000..1d0c8f0bd --- /dev/null +++ b/db/versions/11018-crimsonBamboo/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE vn.productionConfig ADD collection_new_lockname varchar(100) DEFAULT 'collection_new' NOT NULL COMMENT 'Lockname value for proc vn.collection_new'; +ALTER TABLE vn.productionConfig ADD collection_assign_lockname varchar(100) DEFAULT 'collection_assign' NULL COMMENT 'Lockname value for proc vn.collection_new'; diff --git a/db/versions/11021-bronzeErica/00-firstScript.sql b/db/versions/11021-bronzeErica/00-firstScript.sql new file mode 100644 index 000000000..6f6b68d49 --- /dev/null +++ b/db/versions/11021-bronzeErica/00-firstScript.sql @@ -0,0 +1,13 @@ + + ALTER TABLE vn.productionConfig + DROP COLUMN IF EXISTS collectionNewLockname, + DROP COLUMN IF EXISTS collectionAssignLockname; + + DELIMITER $$ + CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`connection_kill`() + BEGIN + + END$$ + DELIMITER ; + + GRANT EXECUTE ON PROCEDURE util.connection_kill TO 'developer'; \ No newline at end of file diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 9a3a1f52a..93a54393d 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -223,7 +223,7 @@ "printerNotExists": "The printer does not exist", "There are not picking tickets": "There are not picking tickets", "ticketCommercial": "The ticket {{ ticket }} for the salesperson {{ salesMan }} is in preparation. (automatically generated message)", - "This password can only be changed by the user themselves": "This password can only be changed by the user themselves", - "They're not your subordinate": "They're not your subordinate", + "This password can only be changed by the user themselves": "This password can only be changed by the user themselves", + "They're not your subordinate": "They're not your subordinate", "InvoiceIn is already booked": "InvoiceIn is already booked" } \ No newline at end of file diff --git a/modules/route/back/methods/route/getExpeditionSummary.js b/modules/route/back/methods/route/getExpeditionSummary.js index ee89401a8..2bd2ca43a 100644 --- a/modules/route/back/methods/route/getExpeditionSummary.js +++ b/modules/route/back/methods/route/getExpeditionSummary.js @@ -49,8 +49,7 @@ module.exports = Self => { JOIN vn.agencyMode am ON am.id = r.agencyModeFk JOIN vn.agency ag ON ag.id = am.agencyFk LEFT JOIN vn.userConfig uc ON uc.userFk = account.myUser_getId() - WHERE (r.created = util.VN_CURDATE() OR r.created = util.yesterday()) - AND t.routeFk = ? + WHERE t.routeFk = ? GROUP BY t.addressFk, e.itemPackingTypeFk ) sub GROUP BY addressFk diff --git a/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js b/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js index de2817d87..668a991f4 100644 --- a/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js +++ b/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js @@ -92,9 +92,7 @@ describe('ticket-request confirm()', () => { const request = await models.TicketRequest.findById(requestId, null, options); expect(request.saleFk).toBeNull(); - - await request.updateAttributes({saleFk: 2}, options); - + await request.updateAttributes({saleFk: 2}); ctx.args = { itemFk: itemId, id: requestId, @@ -102,7 +100,6 @@ describe('ticket-request confirm()', () => { }; await models.TicketRequest.confirm(ctx, options); - await tx.rollback(); } catch (e) { await tx.rollback(); diff --git a/modules/ticket/back/methods/ticket/addSaleByCode.js b/modules/ticket/back/methods/ticket/addSaleByCode.js index a73628c86..ca3d2cb07 100644 --- a/modules/ticket/back/methods/ticket/addSaleByCode.js +++ b/modules/ticket/back/methods/ticket/addSaleByCode.js @@ -30,7 +30,7 @@ module.exports = Self => { }); Self.addSaleByCode = async(ctx, barcode, quantity, ticketFk, warehouseFk, options) => { - const myOptions = {}; + const myOptions = {userId: ctx.req.accessToken.userId}; let tx; if (typeof options == 'object') diff --git a/modules/ticket/back/models/ticket-config.json b/modules/ticket/back/models/ticket-config.json index d757fbd1a..6dd2808ea 100644 --- a/modules/ticket/back/models/ticket-config.json +++ b/modules/ticket/back/models/ticket-config.json @@ -23,6 +23,16 @@ }, "daysForWarningClaim": { "type": "number" + }, + "defaultAttenderFk": { + "type": "number" + } + }, + "relations": { + "attender": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "defaultAttenderFk" } } } diff --git a/modules/ticket/back/models/ticket-request.js b/modules/ticket/back/models/ticket-request.js index d133f85d5..622cd7696 100644 --- a/modules/ticket/back/models/ticket-request.js +++ b/modules/ticket/back/models/ticket-request.js @@ -8,21 +8,21 @@ module.exports = function(Self) { require('../methods/ticket-request/getItemTypeWorker')(Self); Self.observe('before save', async function(ctx) { - if (ctx.isNewInstance) { - const loopBackContext = LoopBackContext.getCurrentContext(); - const filter = {where: {id: loopBackContext.active.accessToken.userId}}; - const models = Self.app.models; - const worker = await models.Worker.findOne(filter); + const loopBackContext = LoopBackContext.getCurrentContext(); + const filter = {where: {id: loopBackContext.active.accessToken.userId}}; + const models = Self.app.models; + const worker = await models.Worker.findOne(filter); + const instance = ctx.instance; + const attenderFk = instance?.attenderFk; - const instance = ctx.instance; + if (ctx.isNewInstance) { instance.requesterFk = worker.id; const httpCtx = {req: loopBackContext.active}; const httpRequest = httpCtx.req.http .req; const $t = httpRequest.__; - const attenderId = instance.attenderFk; - if (attenderId) { + if (attenderFk) { const ticket = await models.Ticket.findById(instance.ticketFk); let messageText = 'New ticket request has been created'; if (instance.price) @@ -35,8 +35,20 @@ module.exports = function(Self) { quantity: instance.quantity, price: instance.price }); - await models.Chat.sendCheckingPresence(httpCtx, attenderId, message); + await models.Chat.sendCheckingPresence(httpCtx, attenderFk, message); + } else { + const {defaultAttenderFk} = await models.TicketConfig.findOne(); + Object.assign(instance, {attenderFk: defaultAttenderFk}); } } }); + + Self.observe('after save', async function(ctx) { + const models = Self.app.models; + const instance = ctx.instance; + if (instance?.attenderFk === null && !ctx.isNewInstance) { + const {defaultAttenderFk} = await models.TicketConfig.findOne(); + await models.TicketRequest.updateAll({id: instance.id}, {attenderFk: defaultAttenderFk}); + } + }); };