diff --git a/back/methods/collection/getAddress.js b/back/methods/collection/getAddress.js new file mode 100644 index 000000000..3fd4b9e6e --- /dev/null +++ b/back/methods/collection/getAddress.js @@ -0,0 +1,20 @@ +module.exports = Self => { + Self.remoteMethod('getAddress', { + description: 'Get all activated address last year ', + accessType: 'READ', + returns: { + type: 'Object', + root: true + }, + http: { + path: `/getAddress`, + verb: 'GET' + } + }); + + Self.getAddress = async() => { + const query = `CALL vn.address_getLosesLastYear()`; + const [result] = await Self.rawSql(query); + return result; + }; +}; diff --git a/back/methods/collection/spec/getAddress.spec.js b/back/methods/collection/spec/getAddress.spec.js new file mode 100644 index 000000000..aac769aa3 --- /dev/null +++ b/back/methods/collection/spec/getAddress.spec.js @@ -0,0 +1,10 @@ +const {models} = require('vn-loopback/server/server'); + +describe('getAddress()', () => { + fit('return list of address last year', async() => { + let response = await models.Collection.getAddress(); + + expect(response.length).toBeGreaterThan(0); + expect(response[0].addressFk).toEqual(1); + }); +}); diff --git a/back/models/collection.js b/back/models/collection.js index a41742ee7..75cdb1174 100644 --- a/back/models/collection.js +++ b/back/models/collection.js @@ -4,4 +4,5 @@ module.exports = Self => { require('../methods/collection/getSectors')(Self); require('../methods/collection/setSaleQuantity')(Self); require('../methods/collection/previousLabel')(Self); + require('../methods/collection/getAddress')(Self); }; diff --git a/db/changes/233801/00-address_getLosesLastYear.sql b/db/changes/233801/00-address_getLosesLastYear.sql new file mode 100644 index 000000000..3b8fa209b --- /dev/null +++ b/db/changes/233801/00-address_getLosesLastYear.sql @@ -0,0 +1,15 @@ + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`address_getLosesLastYear`() +BEGIN + SELECT t.addressFk , a.nickname, c.name + FROM ticket t + JOIN address a ON a.id = t.addressFk + JOIN client c ON a.clientFk = c.id + WHERE c.typeFk = 'loses' + AND a.isactive = 1 + AND t.created >= (CURRENT_DATE() - INTERVAL 1 YEAR) + GROUP BY t.addressFk; +END$$ +DELIMITER ; + diff --git a/db/changes/233801/00-item_setVisibleDiscard.sql b/db/changes/233801/00-item_setVisibleDiscard.sql new file mode 100644 index 000000000..1b9bf0ffb --- /dev/null +++ b/db/changes/233801/00-item_setVisibleDiscard.sql @@ -0,0 +1,65 @@ + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_setVisibleDiscard`( + vItemFk INT, + vWarehouseFk INT, + vQuantity INT, + vAddressFk INT) + +BEGIN + DECLARE vTicketFk INT; + DECLARE vClientFk INT; + DECLARE vCompanyVnlFk INT; + DECLARE vCalc INT; + + SELECT barcodeToItem(vItemFk) INTO vItemFk; + + SELECT companyDefaultFk INTO vCompanyVnlFk + FROM ticketConfig ; + + SELECT c.id INTO vClientFk + FROM client c + JOIN address a ON a.clientFk = c.id + WHERE a.id = vAddressFk; + + SELECT t.id INTO vTicketFk + FROM ticket t + JOIN address a ON a.id = t.addressFk + WHERE t.warehouseFk = vWarehouseFk + AND t.clientFk = vClientFk + AND DATE(t.shipped) = util.VN_CURDATE() + AND a.isDefaultAddress + LIMIT 1; + + CALL cache.visible_refresh(vCalc, TRUE, vWarehouseFk); + + IF vTicketFk IS NULL THEN + CALL ticket_add( + vClientFk, + util.VN_CURDATE(), + vWarehouseFk, + vCompanyVnlFk, + NULL, + NULL, + NULL, + util.VN_CURDATE(), + account.myUser_getId(), + FALSE, + vTicketFk); + END IF; + + INSERT INTO sale(ticketFk, itemFk, concept, quantity) + SELECT vTicketFk, + vItemFk, + CONCAT(longName,' ', getWorkerCode(), ' ', 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/db/changes/233801/00-ticketConfig.sql b/db/changes/233801/00-ticketConfig.sql new file mode 100644 index 000000000..d80dcd7ab --- /dev/null +++ b/db/changes/233801/00-ticketConfig.sql @@ -0,0 +1,13 @@ + +ALTER TABLE `vn`.`ticketConfig` ADD companyDefaultFk int(10) unsigned DEFAULT 442 NOT NULL COMMENT 'Compañía por defecto para crear ticket'; + +ALTER TABLE `vn`.`ticketConfig` ADD CONSTRAINT ticketConfig_FK FOREIGN KEY (companyDefaultFk) REFERENCES vn.company(id) ON DELETE CASCADE ON UPDATE CASCADE; + +-- Se desactivan por utilizarse muy poco + +UPDATE vn.address + SET isDefaultAddress = 0, + isActive = 0 + WHERE id IN (6,47); + + INSERT INTO `salix`.`ACL` (id, model, property, accessType, permission, principalType, principalId) VALUES(698, 'Item', 'setVisibleDiscard', 'WRITE', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index b01c07461..7ce39287e 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2958,3 +2958,12 @@ INSERT INTO `vn`.`invoiceInSerial` (`code`, `description`, `cplusTerIdNifFk`, `t INSERT INTO `hedera`.`imageConfig` (`id`, `maxSize`, `useXsendfile`, `url`) VALUES (1, 0, 0, 'marvel.com'); + +--fixtures for getaddressLastYear +UPDATE vn.client + SET typeFk='loses' + WHERE id=1101; + +UPDATE vn.ticket + SET created='2023-08-01 00:00:00' + WHERE id=6; \ No newline at end of file diff --git a/modules/item/back/methods/item/setVisibleDiscard.js b/modules/item/back/methods/item/setVisibleDiscard.js new file mode 100644 index 000000000..bcdda1ced --- /dev/null +++ b/modules/item/back/methods/item/setVisibleDiscard.js @@ -0,0 +1,37 @@ +module.exports = Self => { + Self.remoteMethodCtx('setVisibleDiscard', { + description: 'Change visible for item', + accessType: 'WRITE', + accepts: [{ + arg: 'itemFk', + type: 'Number', + required: false, + description: 'The item id' + }, { + arg: 'warehouseFk', + type: 'Number', + required: true, + description: 'The warehouse of item' + }, { + arg: 'quantity', + type: 'Number', + required: true, + description: 'The quantity to modify' + }, + { + arg: 'addressFk', + type: 'Number', + required: true, + description: 'The address id' + }], + http: { + path: `/setVisibleDiscard`, + verb: 'POST' + } + }); + + Self.setVisibleDiscard = async(ctx, itemFk, warehouseFk, quantity, addressFk) => { + const query = `CALL vn.item_setVisibleDiscard(?, ?, ?, ?)`; + await Self.rawSql(query, [itemFk, warehouseFk, quantity, addressFk]); + }; +}; diff --git a/modules/item/back/models/item.js b/modules/item/back/models/item.js index 61c5c2588..eac1ecb7d 100644 --- a/modules/item/back/models/item.js +++ b/modules/item/back/models/item.js @@ -16,6 +16,7 @@ module.exports = Self => { require('../methods/item/createIntrastat')(Self); require('../methods/item/buyerWasteEmail')(Self); require('../methods/item/labelPdf')(Self); + require('../methods/item/setVisibleDiscard')(Self); Self.validatesPresenceOf('originFk', {message: 'Cannot be blank'});