diff --git a/db/changes/10480-june/00-itemType.sql b/db/changes/10480-june/00-itemType.sql deleted file mode 100644 index d201acf37..000000000 --- a/db/changes/10480-june/00-itemType.sql +++ /dev/null @@ -1,5 +0,0 @@ -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; \ No newline at end of file diff --git a/db/changes/10491-august/00-aclBusiness.sql b/db/changes/10491-august/00-aclBusiness.sql new file mode 100644 index 000000000..8ea2c6d83 --- /dev/null +++ b/db/changes/10491-august/00-aclBusiness.sql @@ -0,0 +1,3 @@ +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/changes/10491-august/00-aclUsesMana.sql b/db/changes/10491-august/00-aclUsesMana.sql new file mode 100644 index 000000000..5bb7178dd --- /dev/null +++ b/db/changes/10491-august/00-aclUsesMana.sql @@ -0,0 +1,3 @@ +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/changes/10491-august/00-invoiceInPdf.sql b/db/changes/10491-august/00-invoiceInPdf.sql new file mode 100644 index 000000000..d7dc038aa --- /dev/null +++ b/db/changes/10491-august/00-invoiceInPdf.sql @@ -0,0 +1,4 @@ +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/changes/10490-goldenSummer/00-aclNotification.sql b/db/changes/10500-november/00-aclNotification.sql similarity index 100% rename from db/changes/10490-goldenSummer/00-aclNotification.sql rename to db/changes/10500-november/00-aclNotification.sql diff --git a/db/changes/10500-november/00-itemShelvingACL.sql b/db/changes/10500-november/00-itemShelvingACL.sql new file mode 100644 index 000000000..fc32fe1ed --- /dev/null +++ b/db/changes/10500-november/00-itemShelvingACL.sql @@ -0,0 +1,4 @@ +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/changes/10500-november/00-itemShelvingPlacementSupplyStockACL.sql b/db/changes/10500-november/00-itemShelvingPlacementSupplyStockACL.sql new file mode 100644 index 000000000..25eac8d51 --- /dev/null +++ b/db/changes/10500-november/00-itemShelvingPlacementSupplyStockACL.sql @@ -0,0 +1,4 @@ +INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) +VALUES + ('ItemShelvingPlacementSupplyStock', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); + diff --git a/db/changes/10490-august/00-packingSiteConfig.sql b/db/changes/10500-november/00-packingSiteConfig.sql similarity index 100% rename from db/changes/10490-august/00-packingSiteConfig.sql rename to db/changes/10500-november/00-packingSiteConfig.sql diff --git a/db/changes/10490-august/00-packingSiteUpdate.sql b/db/changes/10500-november/00-packingSiteUpdate.sql similarity index 100% rename from db/changes/10490-august/00-packingSiteUpdate.sql rename to db/changes/10500-november/00-packingSiteUpdate.sql diff --git a/db/changes/10490-august/00-salix_url.sql b/db/changes/10500-november/00-salix_url.sql similarity index 100% rename from db/changes/10490-august/00-salix_url.sql rename to db/changes/10500-november/00-salix_url.sql diff --git a/db/changes/10500-november/00-zone_getPostalCode.sql b/db/changes/10500-november/00-zone_getPostalCode.sql new file mode 100644 index 000000000..58a281cb2 --- /dev/null +++ b/db/changes/10500-november/00-zone_getPostalCode.sql @@ -0,0 +1,54 @@ +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/dump/fixtures.sql b/db/dump/fixtures.sql index 3f364bb42..dfa7da733 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -353,48 +353,48 @@ INSERT INTO `vn`.`clientConfig`(`riskTolerance`, `maxCreditRows`) 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', 46460, 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); + (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 @@ -2047,6 +2047,7 @@ INSERT INTO `vn`.`zoneIncluded` (`zoneFk`, `geoFk`, `isIncluded`) (8, 4, 0), (8, 5, 0), (8, 1, 1), + (9, 7, 1), (10, 14, 1); INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `dated`) diff --git a/db/tests/vn/orderConfirmWithUser.spec.js b/db/tests/vn/orderConfirmWithUser.spec.js deleted file mode 100644 index f2a3d0c4e..000000000 --- a/db/tests/vn/orderConfirmWithUser.spec.js +++ /dev/null @@ -1,37 +0,0 @@ -const app = require('vn-loopback/server/server'); -const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; - -// #1885 -xdescribe('order_confirmWithUser()', () => { - it('should confirm an order', async() => { - let stmts = []; - let stmt; - - stmts.push('START TRANSACTION'); - - let params = { - orderFk: 10, - userId: 9 - }; - // problema: la funcion order_confirmWithUser tiene una transacción, por tanto esta nunca hace rollback - stmt = new ParameterizedSQL('CALL hedera.order_confirmWithUser(?, ?)', [ - params.orderFk, - params.userId - ]); - stmts.push(stmt); - - stmt = new ParameterizedSQL('SELECT confirmed FROM hedera.order WHERE id = ?', [ - params.orderFk - ]); - let orderIndex = stmts.push(stmt) - 1; - - stmts.push('ROLLBACK'); - - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await app.models.Ticket.rawStmt(sql); - - savedDescription = result[orderIndex][0].confirmed; - - expect(savedDescription).toBeTruthy(); - }); -}); diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index cd6d39795..f0d726ed6 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -394,11 +394,18 @@ export default { intrastadCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Intrastat"]', originCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Origin"]', buyerCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Buyer"]', + densityCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Density"]', + openAdvancedSearchButton: 'vn-searchbar .append vn-icon[icon="arrow_drop_down"]', + advancedSearchItemType: 'vn-item-search-panel vn-autocomplete[ng-model="filter.typeFk"]', + advancedSearchButton: 'vn-item-search-panel button[type=submit]', + advancedSmartTableButton: 'vn-item-index vn-button[icon="search"]', + advancedSmartTableGrouping: 'vn-item-index vn-textfield[name=grouping]', weightByPieceCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Weight/Piece"]', saveFieldsButton: '.vn-popover.shown vn-button[label="Save"] > button' }, itemFixedPrice: { add: 'vn-fixed-price vn-icon-button[icon="add_circle"]', + firstItemID: 'vn-fixed-price tr:nth-child(2) vn-autocomplete[ng-model="price.itemFk"]', fourthFixedPrice: 'vn-fixed-price tr:nth-child(5)', fourthItemID: 'vn-fixed-price tr:nth-child(5) vn-autocomplete[ng-model="price.itemFk"]', fourthWarehouse: 'vn-fixed-price tr:nth-child(5) vn-autocomplete[ng-model="price.warehouseFk"]', @@ -408,7 +415,8 @@ export default { fourthMinPrice: 'vn-fixed-price tr:nth-child(5) > td:nth-child(6) > vn-input-number[ng-model="price.minPrice"]', fourthStarted: 'vn-fixed-price tr:nth-child(5) vn-date-picker[ng-model="price.started"]', fourthEnded: 'vn-fixed-price tr:nth-child(5) vn-date-picker[ng-model="price.ended"]', - fourthDeleteIcon: 'vn-fixed-price tr:nth-child(5) > td:nth-child(9) > vn-icon-button[icon="delete"]' + fourthDeleteIcon: 'vn-fixed-price tr:nth-child(5) > td:nth-child(9) > vn-icon-button[icon="delete"]', + orderColumnId: 'vn-fixed-price th[field="itemFk"]' }, itemCreateView: { temporalName: 'vn-item-create vn-textfield[ng-model="$ctrl.item.provisionalName"]', @@ -596,7 +604,14 @@ export default { submitNotesButton: 'button[type=submit]' }, ticketExpedition: { - thirdExpeditionRemoveButton: 'vn-ticket-expedition vn-table div > vn-tbody > vn-tr:nth-child(3) > vn-td:nth-child(1) > vn-icon-button[icon="delete"]', + firstSaleCheckbox: 'vn-ticket-expedition vn-tr:nth-child(1) vn-check[ng-model="expedition.checked"]', + thirdSaleCheckbox: 'vn-ticket-expedition vn-tr:nth-child(3) vn-check[ng-model="expedition.checked"]', + deleteExpeditionButton: 'vn-ticket-expedition vn-tool-bar > vn-button[icon="delete"]', + moveExpeditionButton: 'vn-ticket-expedition vn-tool-bar > vn-button[icon="keyboard_arrow_down"]', + moreMenuWithoutRoute: 'vn-item[name="withoutRoute"]', + moreMenuWithRoute: 'vn-item[name="withRoute"]', + newRouteId: '.vn-dialog.shown vn-textfield[ng-model="$ctrl.newRoute"]', + saveButton: '.vn-dialog.shown [response="accept"]', expeditionRow: 'vn-ticket-expedition vn-table vn-tbody > vn-tr' }, ticketPackages: { @@ -1100,7 +1115,8 @@ export default { anyBuyLine: 'vn-entry-summary tr.dark-row' }, entryBasicData: { - reference: 'vn-entry-basic-data vn-textfield[ng-model="$ctrl.entry.ref"]', + reference: 'vn-entry-basic-data vn-textfield[ng-model="$ctrl.entry.reference"]', + invoiceNumber: 'vn-entry-basic-data vn-textfield[ng-model="$ctrl.entry.invoiceNumber"]', notes: 'vn-entry-basic-data vn-textfield[ng-model="$ctrl.entry.notes"]', observations: 'vn-entry-basic-data vn-textarea[ng-model="$ctrl.entry.observation"]', supplier: 'vn-entry-basic-data vn-autocomplete[ng-model="$ctrl.entry.supplierFk"]', diff --git a/e2e/paths/01-salix/03_smartTable_searchBar_integrations.spec.js b/e2e/paths/01-salix/03_smartTable_searchBar_integrations.spec.js new file mode 100644 index 000000000..4fc280209 --- /dev/null +++ b/e2e/paths/01-salix/03_smartTable_searchBar_integrations.spec.js @@ -0,0 +1,77 @@ +import selectors from '../../helpers/selectors.js'; +import getBrowser from '../../helpers/puppeteer'; + +describe('SmartTable SearchBar integration', () => { + let browser; + let page; + beforeAll(async() => { + browser = await getBrowser(); + page = browser.page; + await page.loginAndModule('salesPerson', 'item'); + await page.waitToClick(selectors.globalItems.searchButton); + }); + + afterAll(async() => { + await browser.close(); + }); + + describe('as filters', () => { + it('should search by type in searchBar', async() => { + await page.waitToClick(selectors.itemsIndex.openAdvancedSearchButton); + await page.autocompleteSearch(selectors.itemsIndex.advancedSearchItemType, 'Anthurium'); + await page.waitToClick(selectors.itemsIndex.advancedSearchButton); + await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 3); + }); + + it('should reload page and have same results', async() => { + await page.reload({ + waitUntil: 'networkidle2' + }); + + await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 3); + }); + + it('should search by grouping in smartTable', async() => { + await page.waitToClick(selectors.itemsIndex.advancedSmartTableButton); + await page.write(selectors.itemsIndex.advancedSmartTableGrouping, '1'); + await page.keyboard.press('Enter'); + await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 2); + }); + + it('should now reload page and have same results', async() => { + await page.reload({ + waitUntil: 'networkidle2' + }); + + await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 2); + }); + }); + + describe('as orders', () => { + it('should order by first id', async() => { + await page.loginAndModule('developer', 'item'); + await page.accessToSection('item.fixedPrice'); + await page.doSearch(); + + const result = await page.waitToGetProperty(selectors.itemFixedPrice.firstItemID, 'value'); + + expect(result).toEqual('1'); + }); + + it('should order by last id', async() => { + await page.waitToClick(selectors.itemFixedPrice.orderColumnId); + const result = await page.waitToGetProperty(selectors.itemFixedPrice.firstItemID, 'value'); + + expect(result).toEqual('13'); + }); + + it('should reload page and have same order', async() => { + await page.reload({ + waitUntil: 'networkidle2' + }); + const result = await page.waitToGetProperty(selectors.itemFixedPrice.firstItemID, 'value'); + + expect(result).toEqual('13'); + }); + }); +}); 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 dd2525f43..f970247e5 100644 --- a/e2e/paths/05-ticket/02_expeditions_and_log.spec.js +++ b/e2e/paths/05-ticket/02_expeditions_and_log.spec.js @@ -18,7 +18,8 @@ describe('Ticket expeditions and log path', () => { }); it(`should delete a former expedition and confirm the remaining expedition are the expected ones`, async() => { - await page.waitToClick(selectors.ticketExpedition.thirdExpeditionRemoveButton); + await page.waitToClick(selectors.ticketExpedition.thirdSaleCheckbox); + await page.waitToClick(selectors.ticketExpedition.deleteExpeditionButton); await page.waitToClick(selectors.globalItems.acceptButton); await page.reloadSection('ticket.card.expedition'); diff --git a/e2e/paths/05-ticket/20_moveExpedition.spec.js b/e2e/paths/05-ticket/20_moveExpedition.spec.js new file mode 100644 index 000000000..cf1c5ded3 --- /dev/null +++ b/e2e/paths/05-ticket/20_moveExpedition.spec.js @@ -0,0 +1,50 @@ +import selectors from '../../helpers/selectors.js'; +import getBrowser from '../../helpers/puppeteer'; + +describe('Ticket expeditions', () => { + let browser; + let page; + + beforeAll(async() => { + browser = await getBrowser(); + page = browser.page; + await page.loginAndModule('production', 'ticket'); + await page.accessToSearchResult('1'); + await page.accessToSection('ticket.card.expedition'); + }); + + afterAll(async() => { + await browser.close(); + }); + + it(`should move one expedition to new ticket withoute route`, async() => { + await page.waitToClick(selectors.ticketExpedition.thirdSaleCheckbox); + await page.waitToClick(selectors.ticketExpedition.moveExpeditionButton); + await page.waitToClick(selectors.ticketExpedition.moreMenuWithoutRoute); + await page.waitToClick(selectors.ticketExpedition.saveButton); + await page.waitForState('ticket.card.summary'); + await page.accessToSection('ticket.card.expedition'); + + await page.waitForSelector(selectors.ticketExpedition.expeditionRow, {}); + const result = await page + .countElement(selectors.ticketExpedition.expeditionRow); + + expect(result).toEqual(1); + }); + + it(`should move one expedition to new ticket with route`, async() => { + await page.waitToClick(selectors.ticketExpedition.firstSaleCheckbox); + await page.waitToClick(selectors.ticketExpedition.moveExpeditionButton); + await page.waitToClick(selectors.ticketExpedition.moreMenuWithRoute); + await page.write(selectors.ticketExpedition.newRouteId, '1'); + await page.waitToClick(selectors.ticketExpedition.saveButton); + await page.waitForState('ticket.card.summary'); + await page.accessToSection('ticket.card.expedition'); + + await page.waitForSelector(selectors.ticketExpedition.expeditionRow, {}); + const result = await page + .countElement(selectors.ticketExpedition.expeditionRow); + + expect(result).toEqual(1); + }); +}); diff --git a/e2e/paths/12-entry/05_basicData.spec.js b/e2e/paths/12-entry/05_basicData.spec.js index c1aa14019..3b5f40c35 100644 --- a/e2e/paths/12-entry/05_basicData.spec.js +++ b/e2e/paths/12-entry/05_basicData.spec.js @@ -19,6 +19,7 @@ describe('Entry basic data path', () => { it('should edit the basic data', async() => { await page.write(selectors.entryBasicData.reference, 'new movement 8'); + await page.write(selectors.entryBasicData.invoiceNumber, 'new movement 8'); await page.write(selectors.entryBasicData.notes, 'new notes'); await page.write(selectors.entryBasicData.observations, ' edited'); await page.autocompleteSearch(selectors.entryBasicData.supplier, 'Plants nick'); @@ -45,6 +46,13 @@ describe('Entry basic data path', () => { expect(result).toEqual('new movement 8'); }); + it('should confirm the invoiceNumber was edited', async() => { + await page.reloadSection('entry.card.basicData'); + const result = await page.waitToGetProperty(selectors.entryBasicData.invoiceNumber, 'value'); + + expect(result).toEqual('new movement 8'); + }); + it('should confirm the note was edited', async() => { const result = await page.waitToGetProperty(selectors.entryBasicData.notes, 'value'); diff --git a/front/core/components/crud-model/crud-model.js b/front/core/components/crud-model/crud-model.js index 4994e1547..1095985dc 100644 --- a/front/core/components/crud-model/crud-model.js +++ b/front/core/components/crud-model/crud-model.js @@ -99,6 +99,18 @@ export default class CrudModel extends ModelProxy { return this.refresh(); } + /** + * Applies a new filter to the model. + * + * @param {Object} params Custom parameters + * @return {Promise} The request promise + */ + + applyParams(params) { + this.userParams = params; + return this.refresh(); + } + removeFilter() { return this.applyFilter(null, null); } diff --git a/front/core/components/searchbar/searchbar.js b/front/core/components/searchbar/searchbar.js index 89b5d7df6..10ec1f608 100644 --- a/front/core/components/searchbar/searchbar.js +++ b/front/core/components/searchbar/searchbar.js @@ -139,8 +139,12 @@ export default class Searchbar extends Component { } removeParam(index) { + const field = this.params[index].key; + this.filterSanitizer(field); + this.params.splice(index, 1); - this.doSearch(this.fromBar(), 'bar'); + this.toRemove = field; + this.doSearch(this.fromBar(), 'removeBar'); } fromBar() { @@ -163,7 +167,7 @@ export default class Searchbar extends Component { let keys = Object.keys(filter); keys.forEach(key => { - if (key == 'search') return; + if (key == 'search' || key == 'tableQ' || key == 'tableOrder') return; let value = filter[key]; let chip; @@ -198,6 +202,7 @@ export default class Searchbar extends Component { let promise = this.onSearch({$params: filter}); promise = promise || this.$q.resolve(); promise.then(data => this.onFilter(filter, source, data)); + this.toBar(filter); } onFilter(filter, source, data) { @@ -238,8 +243,11 @@ export default class Searchbar extends Component { } else { state = this.searchState; - if (filter) + if (filter) { + if (this.tableQ) + filter.tableQ = this.tableQ; params = {q: JSON.stringify(filter)}; + } if (this.$state.is(state)) opts = {location: 'replace'}; } @@ -247,6 +255,12 @@ export default class Searchbar extends Component { this.filter = filter; + if (source == 'removeBar') { + delete params[this.toRemove]; + delete this.model.userParams[this.toRemove]; + this.model.refresh(); + } + if (!filter && this.model) this.model.clear(); if (source != 'state') @@ -269,9 +283,14 @@ export default class Searchbar extends Component { this.model.clear(); return; } + if (Object.keys(filter).length === 0) { + this.filterSanitizer('search'); + if (this.model.userParams) + delete this.model.userParams['search']; + } let where = null; - let params = null; + let params = {}; if (this.exprBuilder) { where = buildFilter(filter, @@ -283,9 +302,89 @@ export default class Searchbar extends Component { params = this.fetchParams({$params: params}); } + this.tableQ = null; + + const hasParams = this.$params.q && Object.keys(JSON.parse(this.$params.q)).length; + if (hasParams) { + const stateFilter = JSON.parse(this.$params.q); + for (let param in stateFilter) { + if (param != 'tableQ' && param != 'orderQ') + this.filterSanitizer(param); + } + + for (let param in this.suggestedFilter) { + this.filterSanitizer(param); + delete stateFilter[param]; + } + + this.tableQ = stateFilter.tableQ; + for (let param in stateFilter.tableQ) + params[param] = stateFilter.tableQ[param]; + + Object.assign(stateFilter, params); + return this.model.applyParams(params) + .then(() => this.model.data); + } + return this.model.applyFilter(where ? {where} : null, params) .then(() => this.model.data); } + + filterSanitizer(field) { + if (!field) return; + const userFilter = this.model.userFilter; + const userParams = this.model.userParams; + const where = userFilter && userFilter.where; + + if (this.model.userParams) + delete this.model.userParams[field]; + + if (this.exprBuilder) { + const param = this.exprBuilder({ + param: field, + value: null + }); + if (param) [field] = Object.keys(param); + } + + if (!where) return; + + const whereKeys = Object.keys(where); + for (let key of whereKeys) { + removeProp(where, field, key); + + if (Object.keys(where).length == 0) + delete userFilter.where; + } + + function removeProp(obj, targetProp, prop) { + if (prop == targetProp) + delete obj[prop]; + + if (prop === 'and' || prop === 'or' && obj[prop]) { + const arrayCopy = obj[prop].slice(); + for (let param of arrayCopy) { + const [key] = Object.keys(param); + const index = obj[prop].findIndex(param => { + return Object.keys(param)[0] == key; + }); + if (key == targetProp) + obj[prop].splice(index, 1); + + if (param[key] instanceof Array) + removeProp(param, field, key); + + if (Object.keys(param).length == 0) + obj[prop].splice(index, 1); + } + + if (obj[prop].length == 0) + delete obj[prop]; + } + } + + return {userFilter, userParams}; + } } ngModule.vnComponent('vnSearchbar', { diff --git a/front/core/components/searchbar/searchbar.spec.js b/front/core/components/searchbar/searchbar.spec.js index e4f58d294..ed8fd9d07 100644 --- a/front/core/components/searchbar/searchbar.spec.js +++ b/front/core/components/searchbar/searchbar.spec.js @@ -6,7 +6,7 @@ describe('Component vnSearchbar', () => { let $state; let $params; let $scope; - let filter = {id: 1, search: 'needle'}; + const filter = {id: 1, search: 'needle'}; beforeEach(ngModule('vnCore', $stateProvider => { $stateProvider @@ -70,8 +70,8 @@ describe('Component vnSearchbar', () => { describe('filter() setter', () => { it(`should update the bar params and search`, () => { - let withoutHours = new Date(2000, 1, 1); - let withHours = new Date(withoutHours.getTime()); + const withoutHours = new Date(2000, 1, 1); + const withHours = new Date(withoutHours.getTime()); withHours.setHours(12, 30, 15, 10); controller.filter = { @@ -83,8 +83,8 @@ describe('Component vnSearchbar', () => { myObjectProp: {myProp: 1} }; - let chips = {}; - for (let param of controller.params || []) + const chips = {}; + for (const param of controller.params || []) chips[param.key] = param.chip; expect(controller.searchString).toBe('needle'); @@ -172,13 +172,22 @@ describe('Component vnSearchbar', () => { describe('removeParam()', () => { it(`should remove the parameter from the filter`, () => { jest.spyOn(controller, 'doSearch'); + controller.model = { + refresh: jest.fn(), + userParams: { + id: 1 + } + }; + + controller.model.applyParams = jest.fn().mockReturnValue(Promise.resolve()); + jest.spyOn(controller.model, 'applyParams'); controller.filter = filter; controller.removeParam(0); expect(controller.doSearch).toHaveBeenCalledWith({ search: 'needle' - }, 'bar'); + }, 'removeBar'); }); }); @@ -199,7 +208,7 @@ describe('Component vnSearchbar', () => { it(`should go to the summary state when one result`, () => { jest.spyOn($state, 'go'); - let data = [{id: 1}]; + const data = [{id: 1}]; controller.baseState = 'foo'; controller.onFilter(filter, 'any', data); @@ -214,7 +223,7 @@ describe('Component vnSearchbar', () => { $scope.$apply(); jest.spyOn($state, 'go'); - let data = [{id: 1}]; + const data = [{id: 1}]; controller.baseState = 'foo'; controller.onFilter(filter, 'any', data); @@ -229,7 +238,7 @@ describe('Component vnSearchbar', () => { $scope.$apply(); jest.spyOn($state, 'go'); - let data = [{id: 1}]; + const data = [{id: 1}]; controller.baseState = 'foo'; controller.onFilter(filter, 'any', data); @@ -247,7 +256,7 @@ describe('Component vnSearchbar', () => { controller.onFilter(filter, 'any'); $scope.$apply(); - let queryParams = {q: JSON.stringify(filter)}; + const queryParams = {q: JSON.stringify(filter)}; expect($state.go).toHaveBeenCalledWith('search.state', queryParams, undefined); expect(controller.filter).toEqual(filter); diff --git a/front/core/components/smart-table/index.html b/front/core/components/smart-table/index.html index f26a6b4a2..752019313 100644 --- a/front/core/components/smart-table/index.html +++ b/front/core/components/smart-table/index.html @@ -103,3 +103,4 @@ + diff --git a/front/core/components/smart-table/index.js b/front/core/components/smart-table/index.js index 9e6e7009c..8d2c3c153 100644 --- a/front/core/components/smart-table/index.js +++ b/front/core/components/smart-table/index.js @@ -15,9 +15,17 @@ export default class SmartTable extends Component { this.$inputsScope; this.columns = []; this.autoSave = false; + this.autoState = true; this.transclude(); } + $onChanges() { + if (this.model) { + this.defaultFilter(); + this.defaultOrder(); + } + } + $onDestroy() { const styleElement = document.querySelector('style[id="smart-table"]'); if (this.$.css && styleElement) @@ -47,10 +55,8 @@ export default class SmartTable extends Component { set model(value) { this._model = value; - if (value) { + if (value) this.$.model = value; - this.defaultOrder(); - } } getDefaultViewConfig() { @@ -160,8 +166,36 @@ export default class SmartTable extends Component { } } + defaultFilter() { + if (this.disabledTableFilter || !this.$params.q) return; + + const stateFilter = JSON.parse(this.$params.q).tableQ; + if (!stateFilter || !this.exprBuilder) return; + + const columns = this.columns.map(column => column.field); + + this.displaySearch(); + if (!this.$inputsScope.searchProps) + this.$inputsScope.searchProps = {}; + + for (let param in stateFilter) { + if (columns.includes(param)) { + const whereParams = {[param]: stateFilter[param]}; + Object.assign(this.$inputsScope.searchProps, whereParams); + this.addFilter(param, stateFilter[param]); + } + } + } + defaultOrder() { - const order = this.model.order; + if (this.disabledTableOrder) return; + + let stateOrder; + if (this.$params.q) + stateOrder = JSON.parse(this.$params.q).tableOrder; + + const order = stateOrder ? stateOrder : this.model.order; + if (!order) return; const orderFields = order.split(', '); @@ -195,6 +229,9 @@ export default class SmartTable extends Component { this.setPriority(column.element, priority); } } + + this.model.order = order; + this.refresh(); } registerColumns() { @@ -395,28 +432,54 @@ export default class SmartTable extends Component { } searchByColumn(field) { - const searchCriteria = this.$inputsScope.searchProps[field]; - const emptySearch = searchCriteria === '' || searchCriteria == null; - const filters = this.filterSanitizer(field); if (filters && filters.userFilter) this.model.userFilter = filters.userFilter; - if (!emptySearch) - this.addFilter(field, this.$inputsScope.searchProps[field]); - else this.model.refresh(); + this.addFilter(field, this.$inputsScope.searchProps[field]); + } + + searchPropsSanitizer() { + if (!this.$inputsScope || !this.$inputsScope.searchProps) return null; + let searchProps = this.$inputsScope.searchProps; + const searchPropsArray = Object.entries(searchProps); + searchProps = searchPropsArray.filter( + ([key, value]) => value && value != '' + ); + + return Object.fromEntries(searchProps); } addFilter(field, value) { - let where = {[field]: value}; + if (value == '') value = null; - if (this.exprBuilder) { - where = buildFilter(where, (param, value) => - this.exprBuilder({param, value}) - ); + let stateFilter = {tableQ: {}}; + if (this.$params.q) { + stateFilter = JSON.parse(this.$params.q); + if (!stateFilter.tableQ) + stateFilter.tableQ = {}; + delete stateFilter.tableQ[field]; } - this.model.addFilter({where}); + const whereParams = {[field]: value}; + if (value) { + let where = {[field]: value}; + if (this.exprBuilder) { + where = buildFilter(whereParams, (param, value) => + this.exprBuilder({param, value}) + ); + } + this.model.addFilter({where}); + } + + const searchProps = this.searchPropsSanitizer(); + + Object.assign(stateFilter.tableQ, searchProps); + + const params = {q: JSON.stringify(stateFilter)}; + + this.$state.go(this.$state.current.name, params, {location: 'replace'}); + this.refresh(); } applySort() { @@ -426,7 +489,18 @@ export default class SmartTable extends Component { if (order) this.model.order = order; - this.model.refresh(); + let stateFilter = {tableOrder: {}}; + if (this.$params.q) { + stateFilter = JSON.parse(this.$params.q); + if (!stateFilter.tableOrder) + stateFilter.tableOrder = {}; + } + + stateFilter.tableOrder = order; + + const params = {q: JSON.stringify(stateFilter)}; + this.$state.go(this.$state.current.name, params, {location: 'replace'}); + this.refresh(); } filterSanitizer(field) { @@ -535,6 +609,8 @@ ngModule.vnComponent('smartTable', { autoSave: ' { $httpBackend = _$httpBackend_; $element = $compile(``)($rootScope); controller = $element.controller('smartTable'); + controller.model = { + refresh: jest.fn().mockReturnValue(new Promise(resolve => resolve())), + addFilter: jest.fn(), + userParams: {} + }; })); afterEach(() => { @@ -83,7 +88,7 @@ describe('Component smartTable', () => { describe('defaultOrder', () => { it('should insert a new object to the controller sortCriteria with a sortType value of "ASC"', () => { const element = document.createElement('div'); - controller.model = {order: 'id'}; + controller.model.order = 'id'; controller.columns = [ {field: 'id', element: element}, {field: 'test1', element: element}, @@ -101,7 +106,8 @@ describe('Component smartTable', () => { it('should add new entries to the controller sortCriteria with a sortType values of "ASC" and "DESC"', () => { const element = document.createElement('div'); - controller.model = {order: 'test1, id DESC'}; + controller.model.order = 'test1, id DESC'; + controller.columns = [ {field: 'id', element: element}, {field: 'test1', element: element}, @@ -125,8 +131,6 @@ describe('Component smartTable', () => { describe('addFilter()', () => { it('should call the model addFilter() with a basic where filter if exprBuilder() was not received', () => { - controller.model = {addFilter: jest.fn()}; - controller.addFilter('myField', 'myValue'); const expectedFilter = { @@ -140,7 +144,6 @@ describe('Component smartTable', () => { it('should call the model addFilter() with a built where filter resultant of exprBuilder()', () => { controller.exprBuilder = jest.fn().mockReturnValue({builtField: 'builtValue'}); - controller.model = {addFilter: jest.fn()}; controller.addFilter('myField', 'myValue'); @@ -155,35 +158,48 @@ describe('Component smartTable', () => { }); describe('applySort()', () => { - it('should call the model refresh() without making changes on the model order', () => { - controller.model = {refresh: jest.fn()}; + it('should call the $state go and model refresh without making changes on the model order', () => { + controller.$state = { + go: jest.fn(), + current: { + name: 'section' + } + }; + jest.spyOn(controller, 'refresh'); controller.applySort(); expect(controller.model.order).toBeUndefined(); - expect(controller.model.refresh).toHaveBeenCalled(); + expect(controller.$state.go).toHaveBeenCalled(); + expect(controller.refresh).toHaveBeenCalled(); }); - it('should call the model.refresh() after setting model order according to the controller sortCriteria', () => { - controller.model = {refresh: jest.fn()}; + it('should call the $state go and model refresh after setting model order according to the controller sortCriteria', () => { const orderBy = {field: 'myField', sortType: 'ASC'}; + controller.$state = { + go: jest.fn(), + current: { + name: 'section' + } + }; + jest.spyOn(controller, 'refresh'); + controller.sortCriteria = [orderBy]; controller.applySort(); expect(controller.model.order).toEqual(`${orderBy.field} ${orderBy.sortType}`); - expect(controller.model.refresh).toHaveBeenCalled(); + expect(controller.$state.go).toHaveBeenCalled(); + expect(controller.refresh).toHaveBeenCalled(); }); }); describe('filterSanitizer()', () => { it('should remove the where filter after leaving no fields in it', () => { - controller.model = { - userFilter: { - where: {fieldToRemove: 'valueToRemove'} - }, - userParams: {} + controller.model.userFilter = { + where: {fieldToRemove: 'valueToRemove'} }; + controller.model.userParams = {}; const result = controller.filterSanitizer('fieldToRemove'); @@ -193,23 +209,21 @@ describe('Component smartTable', () => { }); it('should remove the where filter after leaving no fields and "empty ands/ors" in it', () => { - controller.model = { - userFilter: { - where: { - and: [ - {aFieldToRemove: 'aValueToRemove'}, - {aFieldToRemove: 'aValueToRemove'}, - { - or: [ - {aFieldToRemove: 'aValueToRemove'}, - {aFieldToRemove: 'aValueToRemove'}, - ] - } - ] - } - }, - userParams: {} - }; + controller.model.userFilter = { + where: { + and: [ + {aFieldToRemove: 'aValueToRemove'}, + {aFieldToRemove: 'aValueToRemove'}, + { + or: [ + {aFieldToRemove: 'aValueToRemove'}, + {aFieldToRemove: 'aValueToRemove'}, + ] + } + ] + } + }, + controller.model.userParams = {}; const result = controller.filterSanitizer('aFieldToRemove'); @@ -219,24 +233,22 @@ describe('Component smartTable', () => { }); it('should not remove the where filter after leaving no empty "ands/ors" in it', () => { - controller.model = { - userFilter: { - where: { - and: [ - {aFieldToRemove: 'aValueToRemove'}, - {aFieldToRemove: 'aValueToRemove'}, - { - or: [ - {aFieldToRemove: 'aValueToRemove'}, - {aFieldToRemove: 'aValueToRemove'}, - ] - } - ], - or: [{dontKillMe: 'thanks'}] - } - }, - userParams: {} + controller.model.userFilter = { + where: { + and: [ + {aFieldToRemove: 'aValueToRemove'}, + {aFieldToRemove: 'aValueToRemove'}, + { + or: [ + {aFieldToRemove: 'aValueToRemove'}, + {aFieldToRemove: 'aValueToRemove'}, + ] + } + ], + or: [{dontKillMe: 'thanks'}] + } }; + controller.model.userParams = {}; const result = controller.filterSanitizer('aFieldToRemove'); @@ -249,7 +261,7 @@ describe('Component smartTable', () => { describe('saveAll()', () => { it('should throw an error if there are no changes to save in the model', () => { jest.spyOn(controller.vnApp, 'showError'); - controller.model = {isChanged: false}; + controller.model.isChanged = false; controller.saveAll(); expect(controller.vnApp.showError).toHaveBeenCalledWith('No changes to save'); @@ -258,10 +270,8 @@ describe('Component smartTable', () => { it('should call the showSuccess() if there are changes to save in the model', done => { jest.spyOn(controller.vnApp, 'showSuccess'); - controller.model = { - save: jest.fn().mockReturnValue(Promise.resolve()), - isChanged: true - }; + controller.model.save = jest.fn().mockReturnValue(Promise.resolve()); + controller.model.isChanged = true; controller.saveAll().then(() => { expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); @@ -269,4 +279,43 @@ describe('Component smartTable', () => { }).catch(done.fail); }); }); + + describe('defaultFilter()', () => { + it('should call model refresh and model addFilter with filter', () => { + controller.exprBuilder = jest.fn().mockReturnValue({builtField: 'builtValue'}); + + controller.$params = { + q: '{"tableQ": {"fieldName":"value"}}' + }; + controller.columns = [ + {field: 'fieldName'} + ]; + controller.$inputsScope = { + searchProps: {} + }; + jest.spyOn(controller, 'refresh'); + + controller.defaultFilter(); + + expect(controller.model.addFilter).toHaveBeenCalled(); + expect(controller.refresh).toHaveBeenCalled(); + }); + }); + + describe('searchPropsSanitizer()', () => { + it('should searchProps sanitize', () => { + controller.$inputsScope = { + searchProps: { + filterOne: '1', + filterTwo: '' + } + }; + const searchPropsExpected = { + filterOne: '1' + }; + const newSearchProps = controller.searchPropsSanitizer(); + + expect(newSearchProps).toEqual(searchPropsExpected); + }); + }); }); diff --git a/front/salix/locale/es.yml b/front/salix/locale/es.yml index e5dc82b16..d92c32b33 100644 --- a/front/salix/locale/es.yml +++ b/front/salix/locale/es.yml @@ -51,6 +51,7 @@ Entries: Entradas Users: Usuarios Suppliers: Proveedores Monitors: Monitores +Shelvings: Carros # Common diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 9c2882720..87fe4b10c 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -240,6 +240,7 @@ "Modifiable user details only by an administrator": "Detalles de usuario modificables solo por un administrador", "Modifiable password only via recovery or by an administrator": "Contraseña modificable solo a través de la recuperación o por un administrador", "Not enough privileges to edit a client": "No tienes suficientes privilegios para editar un cliente", + "This route does not exists": "Esta ruta no existe", "Claim pickup order sent": "Reclamación Orden de recogida enviada [({{claimId}})]({{{claimUrl}}}) al cliente *{{clientName}}*", "You don't have grant privilege": "No tienes privilegios para dar privilegios", "You don't own the role and you can't assign it to another user": "No eres el propietario del rol y no puedes asignarlo a otro usuario", diff --git a/modules/account/back/models/ldap-config.js b/modules/account/back/models/ldap-config.js index 819659066..a2a2684a9 100644 --- a/modules/account/back/models/ldap-config.js +++ b/modules/account/back/models/ldap-config.js @@ -5,6 +5,8 @@ const crypto = require('crypto'); const nthash = require('smbhash').nthash; module.exports = Self => { + const shouldSync = process.env.NODE_ENV !== 'test'; + Self.getSynchronizer = async function() { return await Self.findOne({ fields: [ @@ -30,6 +32,7 @@ module.exports = Self => { }, async syncUser(userName, info, password) { + let { client, accountConfig @@ -130,13 +133,14 @@ module.exports = Self => { })); } - if (changes.length) + if (shouldSync && changes.length) await client.modify(dn, changes); - } else + } else if (shouldSync) await client.add(dn, newEntry); } else { try { - await client.del(dn); + if (shouldSync) + await client.del(dn); console.log(` -> User '${userName}' removed from LDAP`); } catch (e) { if (e.name !== 'NoSuchObjectError') throw e; @@ -196,17 +200,19 @@ module.exports = Self => { for (let group of groups) { try { let dn = `cn=${group},${groupDn}`; - await client.modify(dn, new ldap.Change({ - operation, - modification: {memberUid: userName} - })); + if (shouldSync) { + await client.modify(dn, new ldap.Change({ + operation, + modification: {memberUid: userName} + })); + } } catch (err) { if (err.name !== 'NoSuchObjectError') throw err; } } } - + await applyOperations(deleteGroups, 'delete'); await applyOperations(addGroups, 'add'); }, @@ -266,8 +272,10 @@ module.exports = Self => { filter: 'objectClass=posixGroup' }; let reqs = []; - await client.searchForeach(this.groupDn, opts, - o => reqs.push(client.del(o.dn))); + await client.searchForeach(this.groupDn, opts, object => { + if (shouldSync) + reqs.push(client.del(object.dn)); + }); await Promise.all(reqs); // Recreate roles @@ -291,7 +299,8 @@ module.exports = Self => { } let dn = `cn=${role.name},${this.groupDn}`; - reqs.push(client.add(dn, newEntry)); + if (shouldSync) + reqs.push(client.add(dn, newEntry)); } await Promise.all(reqs); } diff --git a/modules/account/back/models/samba-config.js b/modules/account/back/models/samba-config.js index 5fd62a68b..168b5ffb4 100644 --- a/modules/account/back/models/samba-config.js +++ b/modules/account/back/models/samba-config.js @@ -60,16 +60,19 @@ module.exports = Self => { return `cn=Users,${dnBase}`; }, - async syncUser(userName, info, password) { + async syncUser(userName, info, password) { let {sshClient} = this; - + let sambaUser = await this.adClient.searchOne(this.usersDn(), { scope: 'sub', attributes: ['userAccountControl'], filter: `(&(objectClass=user)(sAMAccountName=${userName}))` }); let isEnabled = sambaUser - && !(sambaUser.userAccountControl & UserAccountControlFlags.ACCOUNTDISABLE); + && !(sambaUser.userAccountControl & UserAccountControlFlags.ACCOUNTDISABLE); + + if (process.env.NODE_ENV === 'test') + return; if (info.hasAccount) { if (!sambaUser) { diff --git a/modules/claim/front/routes.json b/modules/claim/front/routes.json index d02ea6f6c..a8b958c5f 100644 --- a/modules/claim/front/routes.json +++ b/modules/claim/front/routes.json @@ -73,7 +73,7 @@ { "url": "/note", "state": "claim.card.note", - "component": "ui-view", + "component": "ui-view", "abstract": true, "acl": ["salesPerson"] }, @@ -105,7 +105,7 @@ "acl": ["claimManager"] }, { - "url": "/action", + "url": "/action?q", "state": "claim.card.action", "component": "vn-claim-action", "description": "Action", @@ -131,4 +131,4 @@ "acl": ["claimManager"] } ] -} \ No newline at end of file +} diff --git a/modules/client/back/methods/client/filter.js b/modules/client/back/methods/client/filter.js new file mode 100644 index 000000000..3e1ea43bb --- /dev/null +++ b/modules/client/back/methods/client/filter.js @@ -0,0 +1,147 @@ + +const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; +const buildFilter = require('vn-loopback/util/filter').buildFilter; +const mergeFilters = require('vn-loopback/util/filter').mergeFilters; + +module.exports = Self => { + Self.remoteMethodCtx('filter', { + description: 'Find all clients matched by the filter', + accessType: 'READ', + accepts: [ + { + arg: 'filter', + type: 'object', + }, + { + arg: 'search', + type: 'string', + description: `If it's and integer searchs by id, otherwise it searchs by name`, + }, + { + arg: 'name', + type: 'string', + description: 'The client name', + }, + { + arg: 'salesPersonFk', + type: 'number', + }, + { + arg: 'fi', + type: 'string', + description: 'The client fiscal id', + }, + { + arg: 'socialName', + type: 'string', + }, + { + arg: 'city', + type: 'string', + }, + { + arg: 'postcode', + type: 'string', + }, + { + arg: 'provinceFk', + type: 'number', + }, + { + arg: 'email', + type: 'string', + }, + { + arg: 'phone', + type: 'string', + }, + { + arg: 'zoneFk', + type: 'number', + }, + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/filter`, + verb: 'GET' + } + }); + + Self.filter = async(ctx, filter, options) => { + const conn = Self.dataSource.connector; + const myOptions = {}; + const postalCode = []; + const args = ctx.args; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (args.zoneFk) { + query = `CALL vn.zone_getPostalCode(?)`; + const [geos] = await Self.rawSql(query, [args.zoneFk]); + for (let geo of geos) + postalCode.push(geo.name); + } + + const where = buildFilter(ctx.args, (param, value) => { + switch (param) { + case 'search': + return /^\d+$/.test(value) + ? {'c.id': {inq: value}} + : {'c.name': {like: `%${value}%`}}; + case 'name': + case 'salesPersonFk': + case 'fi': + case 'socialName': + case 'city': + case 'postcode': + case 'provinceFk': + case 'email': + case 'phone': + param = `c.${param}`; + return {[param]: value}; + case 'zoneFk': + param = 'a.postalCode'; + return {[param]: {inq: postalCode}}; + } + }); + + filter = mergeFilters(filter, {where}); + + const stmts = []; + const stmt = new ParameterizedSQL( + `SELECT + DISTINCT c.id, + c.name, + c.fi, + c.socialName, + c.phone, + c.city, + c.postcode, + c.email, + c.isActive, + c.isFreezed, + p.id AS provinceFk, + p.name AS province, + u.id AS salesPersonFk, + u.name AS salesPerson + FROM client c + LEFT JOIN account.user u ON u.id = c.salesPersonFk + LEFT JOIN province p ON p.id = c.provinceFk + JOIN vn.address a ON a.clientFk = c.id + ` + ); + + stmt.merge(conn.makeWhere(filter.where)); + stmt.merge(conn.makePagination(filter)); + + const clientsIndex = stmts.push(stmt) - 1; + const sql = ParameterizedSQL.join(stmts, ';'); + const result = await conn.executeStmt(sql, myOptions); + + return clientsIndex === 0 ? result : result[clientsIndex]; + }; +}; diff --git a/modules/client/back/methods/client/specs/filter.spec.js b/modules/client/back/methods/client/specs/filter.spec.js new file mode 100644 index 000000000..679585050 --- /dev/null +++ b/modules/client/back/methods/client/specs/filter.spec.js @@ -0,0 +1,199 @@ +const {models} = require('vn-loopback/server/server'); + +describe('client filter()', () => { + it('should return the clients matching the filter with a limit of 20 rows', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 1}}, args: {}}; + const filter = {limit: '8'}; + const result = await models.Client.filter(ctx, filter, options); + + expect(result.length).toEqual(8); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the client "Bruce Wayne" matching the search argument with his name', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 1}}, args: {search: 'Bruce Wayne'}}; + const filter = {}; + const result = await models.Client.filter(ctx, filter, options); + + const firstResult = result[0]; + + expect(result.length).toEqual(1); + expect(firstResult.name).toEqual('Bruce Wayne'); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the client "Bruce Wayne" matching the search argument with his id', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 1}}, args: {search: '1101'}}; + const filter = {}; + const result = await models.Client.filter(ctx, filter, options); + + const firstResult = result[0]; + + expect(result.length).toEqual(1); + expect(firstResult.name).toEqual('Bruce Wayne'); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the client "Bruce Wayne" matching the name argument', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 1}}, args: {name: 'Bruce Wayne'}}; + const filter = {}; + const result = await models.Client.filter(ctx, filter, options); + + const firstResult = result[0]; + + expect(result.length).toEqual(1); + expect(firstResult.name).toEqual('Bruce Wayne'); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the clients matching the "salesPersonFk" argument', async() => { + const tx = await models.Client.beginTransaction({}); + const salesPersonId = 18; + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 1}}, args: {salesPersonFk: salesPersonId}}; + const filter = {}; + const result = await models.Client.filter(ctx, filter, options); + + const randomIndex = Math.floor(Math.random() * result.length); + const randomResultClient = result[randomIndex]; + + expect(result.length).toBeGreaterThanOrEqual(5); + expect(randomResultClient.salesPersonFk).toEqual(salesPersonId); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the clients matching the "fi" argument', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 1}}, args: {fi: '251628698'}}; + const filter = {}; + const result = await models.Client.filter(ctx, filter, options); + + const firstClient = result[0]; + + expect(result.length).toEqual(1); + expect(firstClient.name).toEqual('Max Eisenhardt'); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the clients matching the "city" argument', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 1}}, args: {city: 'Gotham'}}; + const filter = {}; + const result = await models.Client.filter(ctx, filter, options); + + const randomIndex = Math.floor(Math.random() * result.length); + const randomResultClient = result[randomIndex]; + + expect(result.length).toBeGreaterThanOrEqual(20); + expect(randomResultClient.city.toLowerCase()).toEqual('gotham'); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the clients matching the "postcode" argument', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 1}}, args: {postcode: '46460'}}; + const filter = {}; + const result = await models.Client.filter(ctx, filter, options); + + const randomIndex = Math.floor(Math.random() * result.length); + const randomResultClient = result[randomIndex]; + + expect(result.length).toBeGreaterThanOrEqual(20); + expect(randomResultClient.postcode).toEqual('46460'); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the clients matching the "zoneFk" argument', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 1}}, args: {zoneFk: 9}}; + const filter = {}; + const result = await models.Client.filter(ctx, filter, options); + + expect(result.length).toBe(1); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/client/back/model-config.json b/modules/client/back/model-config.json index b2e600610..4ef34ca3a 100644 --- a/modules/client/back/model-config.json +++ b/modules/client/back/model-config.json @@ -8,6 +8,9 @@ "BankEntity": { "dataSource": "vn" }, + "Business": { + "dataSource": "vn" + }, "BusinessType": { "dataSource": "vn" }, diff --git a/modules/client/back/models/business.json b/modules/client/back/models/business.json new file mode 100644 index 000000000..7ad2d307f --- /dev/null +++ b/modules/client/back/models/business.json @@ -0,0 +1,27 @@ +{ + "name": "Business", + "base": "VnModel", + "options": { + "mysql": { + "table": "business" + } + }, + "properties": { + "id": { + "type": "number", + "id": true + } + }, + "relations": { + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + }, + "department": { + "type": "belongsTo", + "model": "Department", + "foreignKey": "departmentFk" + } + } +} \ No newline at end of file diff --git a/modules/client/back/models/client-methods.js b/modules/client/back/models/client-methods.js index 04d10413a..5134e3942 100644 --- a/modules/client/back/models/client-methods.js +++ b/modules/client/back/models/client-methods.js @@ -47,4 +47,5 @@ module.exports = Self => { require('../methods/client/incotermsAuthorizationHtml')(Self); require('../methods/client/incotermsAuthorizationEmail')(Self); require('../methods/client/consumptionSendQueued')(Self); + require('../methods/client/filter')(Self); }; diff --git a/modules/client/front/main/index.html b/modules/client/front/main/index.html index e8bc4b988..0787858ae 100644 --- a/modules/client/front/main/index.html +++ b/modules/client/front/main/index.html @@ -1,6 +1,6 @@ @@ -10,8 +10,7 @@ vn-focus panel="vn-client-search-panel" info="Search client by id or name" - model="model" - expr-builder="$ctrl.exprBuilder(param, value)"> + model="model"> diff --git a/modules/client/front/main/index.js b/modules/client/front/main/index.js index 1069d3487..346880f4c 100644 --- a/modules/client/front/main/index.js +++ b/modules/client/front/main/index.js @@ -2,32 +2,6 @@ import ngModule from '../module'; import ModuleMain from 'salix/components/module-main'; export default class Client extends ModuleMain { - exprBuilder(param, value) { - switch (param) { - case 'search': - return /^\d+$/.test(value) - ? {id: value} - : {or: [{name: {like: `%${value}%`}}, {socialName: {like: `%${value}%`}}]}; - case 'phone': - return { - or: [ - {phone: value}, - {mobile: value} - ] - }; - case 'name': - case 'socialName': - case 'city': - case 'email': - return {[param]: {like: `%${value}%`}}; - case 'id': - case 'fi': - case 'postcode': - case 'provinceFk': - case 'salesPersonFk': - return {[param]: value}; - } - } } ngModule.vnComponent('vnClient', { diff --git a/modules/client/front/routes.json b/modules/client/front/routes.json index c7462e46c..406ca07d7 100644 --- a/modules/client/front/routes.json +++ b/modules/client/front/routes.json @@ -20,7 +20,7 @@ {"state": "client.card.credit.index", "icon": "credit_card"}, {"state": "client.card.greuge.index", "icon": "work"}, {"state": "client.card.balance.index", "icon": "icon-invoice"}, - {"state": "client.card.recovery.index", "icon": "icon-recovery"}, + {"state": "client.card.recovery.index", "icon": "icon-recovery"}, {"state": "client.card.webAccess", "icon": "cloud"}, {"state": "client.card.log", "icon": "history"}, { @@ -37,7 +37,7 @@ {"state": "client.card.unpaid", "icon": "icon-defaulter"} ] } - ] + ] }, "keybindings": [ {"key": "c", "state": "client.index"} @@ -147,7 +147,7 @@ { "url": "/note", "state": "client.card.note", - "component": "ui-view", + "component": "ui-view", "abstract": true }, { @@ -236,7 +236,7 @@ "client": "$ctrl.client" } }, - { + { "url": "/create?payed&companyFk&bankFk&payedAmount", "state": "client.card.balance.create", "component": "vn-client-balance-create", @@ -406,13 +406,13 @@ } }, { - "url": "/defaulter", + "url": "/defaulter?q", "state": "client.defaulter", "component": "vn-client-defaulter", "description": "Defaulter" }, { - "url" : "/notification", + "url" : "/notification?q", "state": "client.notification", "component": "vn-client-notification", "description": "Notifications" @@ -424,7 +424,7 @@ "description": "Unpaid" }, { - "url": "/extended-list", + "url": "/extended-list?q", "state": "client.extendedList", "component": "vn-client-extended-list", "description": "Extended list" diff --git a/modules/client/front/search-panel/index.html b/modules/client/front/search-panel/index.html index 234cb6f53..a02f93882 100644 --- a/modules/client/front/search-panel/index.html +++ b/modules/client/front/search-panel/index.html @@ -58,6 +58,13 @@ value-field="id" label="Province"> + + { e.id, e.supplierFk, e.dated, - e.ref, + e.ref reference, + e.ref invoiceNumber, e.isBooked, e.isExcludedFromAvailable, e.notes, diff --git a/modules/entry/back/methods/entry/importBuys.js b/modules/entry/back/methods/entry/importBuys.js index fb2f5f452..fdc6b058e 100644 --- a/modules/entry/back/methods/entry/importBuys.js +++ b/modules/entry/back/methods/entry/importBuys.js @@ -12,10 +12,15 @@ module.exports = Self => { http: {source: 'path'} }, { - arg: 'ref', + arg: 'reference', type: 'string', description: 'The buyed boxes ids', }, + { + arg: 'invoiceNumber', + type: 'string', + description: 'The registered invoice number', + }, { arg: 'observation', type: 'string', @@ -63,7 +68,8 @@ module.exports = Self => { await entry.updateAttributes({ observation: args.observation, - ref: args.ref + reference: args.reference, + invoiceNumber: args.invoiceNumber }, myOptions); const travel = entry.travel(); diff --git a/modules/entry/back/methods/entry/specs/importBuys.spec.js b/modules/entry/back/methods/entry/specs/importBuys.spec.js index 9cf6f4300..4f9204c6a 100644 --- a/modules/entry/back/methods/entry/specs/importBuys.spec.js +++ b/modules/entry/back/methods/entry/specs/importBuys.spec.js @@ -15,13 +15,15 @@ describe('entry import()', () => { }); it('should import the buy rows', async() => { - const expectedRef = '1, 2'; + const expectedReference = '1, 2'; + const expectedInvoiceNumber = '1, 2'; const expectedObservation = '123456'; const ctx = { req: activeCtx, args: { observation: expectedObservation, - ref: expectedRef, + reference: expectedReference, + invoiceNumber: expectedInvoiceNumber, buys: [ { itemFk: 1, @@ -58,7 +60,8 @@ describe('entry import()', () => { }, options); expect(updatedEntry.observation).toEqual(expectedObservation); - expect(updatedEntry.ref).toEqual(expectedRef); + expect(updatedEntry.reference).toEqual(expectedReference); + expect(updatedEntry.invoiceNumber).toEqual(expectedInvoiceNumber); expect(entryBuys.length).toEqual(4); await tx.rollback(); diff --git a/modules/entry/back/models/entry.json b/modules/entry/back/models/entry.json index c456859a5..d3c802ad2 100644 --- a/modules/entry/back/models/entry.json +++ b/modules/entry/back/models/entry.json @@ -18,8 +18,17 @@ "dated": { "type": "date" }, - "ref": { - "type": "string" + "reference": { + "type": "string", + "mysql": { + "columnName": "ref" + } + }, + "invoiceNumber": { + "type": "string", + "mysql": { + "columnName": "ref" + } }, "isBooked": { "type": "boolean" diff --git a/modules/entry/front/basic-data/index.html b/modules/entry/front/basic-data/index.html index 423e9d70d..68a65e890 100644 --- a/modules/entry/front/basic-data/index.html +++ b/modules/entry/front/basic-data/index.html @@ -48,7 +48,7 @@ @@ -61,17 +61,25 @@ - - + label="Invoice number" + ng-model="$ctrl.entry.invoiceNumber" + rule + vn-focus> + + + - - + + + + Id Landed Reference + Invoice number Supplier Booked Confirmed @@ -45,7 +46,8 @@ {{::entry.landed | date:'dd/MM/yyyy'}} - {{::entry.ref}} + {{::entry.reference}} + {{::entry.invoiceNumber}} {{::entry.supplierName}} diff --git a/modules/entry/front/index/locale/es.yml b/modules/entry/front/index/locale/es.yml index 519f8e39a..4f12fc7bb 100644 --- a/modules/entry/front/index/locale/es.yml +++ b/modules/entry/front/index/locale/es.yml @@ -14,4 +14,5 @@ Booked: Contabilizada Is inventory: Inventario Notes: Notas Status: Estado -Selection: Selección \ No newline at end of file +Selection: Selección +Invoice number: Núm. factura \ No newline at end of file diff --git a/modules/entry/front/search-panel/index.html b/modules/entry/front/search-panel/index.html index 38acdf77d..adcb9d6d4 100644 --- a/modules/entry/front/search-panel/index.html +++ b/modules/entry/front/search-panel/index.html @@ -13,9 +13,16 @@ + ng-model="filter.reference"> + + + + diff --git a/modules/entry/front/search-panel/locale/es.yml b/modules/entry/front/search-panel/locale/es.yml index 88f164145..05b71da99 100644 --- a/modules/entry/front/search-panel/locale/es.yml +++ b/modules/entry/front/search-panel/locale/es.yml @@ -5,4 +5,5 @@ From: Desde To: Hasta Agency: Agencia Warehouse: Almacén -Search entry by id or a suppliers by name or alias: Buscar entrada por id o proveedores por nombre y alias \ No newline at end of file +Search entry by id or a suppliers by name or alias: Buscar entrada por id o proveedores por nombre y alias +Invoice number: Núm. factura \ No newline at end of file diff --git a/modules/entry/front/summary/index.html b/modules/entry/front/summary/index.html index ffd8aafab..04844ab99 100644 --- a/modules/entry/front/summary/index.html +++ b/modules/entry/front/summary/index.html @@ -27,7 +27,10 @@ value="{{$ctrl.entryData.company.code}}"> + value="{{$ctrl.entryData.reference}}"> + + diff --git a/modules/entry/front/summary/locale/es.yml b/modules/entry/front/summary/locale/es.yml index a141ce56c..1761561ed 100644 --- a/modules/entry/front/summary/locale/es.yml +++ b/modules/entry/front/summary/locale/es.yml @@ -8,4 +8,4 @@ Minimum price: Precio mínimo Buys: Compras Travel: Envio Go to the entry: Ir a la entrada - +Invoice number: Núm. factura diff --git a/modules/invoiceIn/back/methods/invoice-in/invoiceInEmail.js b/modules/invoiceIn/back/methods/invoice-in/invoiceInEmail.js new file mode 100644 index 000000000..0768541a8 --- /dev/null +++ b/modules/invoiceIn/back/methods/invoice-in/invoiceInEmail.js @@ -0,0 +1,53 @@ +const {Email} = require('vn-print'); + +module.exports = Self => { + Self.remoteMethodCtx('invoiceInEmail', { + description: 'Sends the invoice in email with an attached PDF', + accessType: 'WRITE', + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + description: 'The invoice id', + http: {source: 'path'} + }, + { + arg: 'recipient', + type: 'string', + description: 'The recipient email', + required: true, + }, + { + arg: 'recipientId', + type: 'number', + description: 'The recipient id to send to the recipient preferred language', + required: false + } + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: '/:id/invoice-in-email', + verb: 'POST' + } + }); + + Self.invoiceInEmail = async ctx => { + const args = Object.assign({}, ctx.args); + const params = { + recipient: args.recipient, + lang: ctx.req.getLocale() + }; + + delete args.ctx; + for (const param in args) + params[param] = args[param]; + + const email = new Email('invoiceIn', params); + + return email.send(); + }; +}; diff --git a/modules/invoiceIn/back/methods/invoice-in/invoiceInPdf.js b/modules/invoiceIn/back/methods/invoice-in/invoiceInPdf.js new file mode 100644 index 000000000..e7962c93f --- /dev/null +++ b/modules/invoiceIn/back/methods/invoice-in/invoiceInPdf.js @@ -0,0 +1,50 @@ +const {Report} = require('vn-print'); + +module.exports = Self => { + Self.remoteMethodCtx('invoiceInPdf', { + description: 'Returns the invoiceIn pdf', + accessType: 'READ', + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + description: 'The invoiceIn id', + http: {source: 'path'} + } + ], + returns: [ + { + arg: 'body', + type: 'file', + root: true + }, { + arg: 'Content-Type', + type: 'String', + http: {target: 'header'} + }, { + arg: 'Content-Disposition', + type: 'String', + http: {target: 'header'} + } + ], + http: { + path: '/:id/invoice-in-pdf', + verb: 'GET' + } + }); + + Self.invoiceInPdf = async(ctx, id) => { + const args = Object.assign({}, ctx.args); + const params = {lang: ctx.req.getLocale()}; + delete args.ctx; + + for (const param in args) + params[param] = args[param]; + + const report = new Report('invoiceIn', params); + const stream = await report.toPdfStream(); + + return [stream, 'application/pdf', `filename="doc-${id}.pdf"`]; + }; +}; diff --git a/modules/invoiceIn/back/models/invoice-in.js b/modules/invoiceIn/back/models/invoice-in.js index 3b5aa65d9..95ccc7b20 100644 --- a/modules/invoiceIn/back/models/invoice-in.js +++ b/modules/invoiceIn/back/models/invoice-in.js @@ -4,4 +4,6 @@ module.exports = Self => { require('../methods/invoice-in/clone')(Self); require('../methods/invoice-in/toBook')(Self); require('../methods/invoice-in/getTotals')(Self); + require('../methods/invoice-in/invoiceInPdf')(Self); + require('../methods/invoice-in/invoiceInEmail')(Self); }; diff --git a/modules/invoiceIn/back/models/invoice-in.json b/modules/invoiceIn/back/models/invoice-in.json index c6a736b06..fa8a1d8f8 100644 --- a/modules/invoiceIn/back/models/invoice-in.json +++ b/modules/invoiceIn/back/models/invoice-in.json @@ -94,6 +94,11 @@ "model": "Supplier", "foreignKey": "supplierFk" }, + "supplierContact": { + "type": "hasMany", + "model": "SupplierContact", + "foreignKey": "supplierFk" + }, "currency": { "type": "belongsTo", "model": "Currency", diff --git a/modules/invoiceIn/front/card/index.js b/modules/invoiceIn/front/card/index.js index 582c2abb8..c7ac08cc7 100644 --- a/modules/invoiceIn/front/card/index.js +++ b/modules/invoiceIn/front/card/index.js @@ -8,6 +8,14 @@ class Controller extends ModuleCard { { relation: 'supplier' }, + { + relation: 'supplierContact', + scope: { + where: { + email: {neq: null} + } + } + }, { relation: 'invoiceInDueDay' }, diff --git a/modules/invoiceIn/front/descriptor/index.html b/modules/invoiceIn/front/descriptor/index.html index 33f9ee8c6..819615c20 100644 --- a/modules/invoiceIn/front/descriptor/index.html +++ b/modules/invoiceIn/front/descriptor/index.html @@ -1,5 +1,5 @@ - @@ -10,7 +10,6 @@ translate> To book - Clone Invoice + + Show agricultural invoice as PDF + + + Send agricultural invoice as PDF +
@@ -37,7 +46,7 @@ - {{$ctrl.invoiceIn.supplier.nickname}} + {{$ctrl.invoiceIn.supplier.nickname}}
@@ -57,9 +66,9 @@ icon="icon-invoice-in"> - + - +
- - \ No newline at end of file + + + + + + Are you sure you want to send it? + + + + + + + + diff --git a/modules/invoiceIn/front/descriptor/index.js b/modules/invoiceIn/front/descriptor/index.js index cde324296..5cd00d743 100644 --- a/modules/invoiceIn/front/descriptor/index.js +++ b/modules/invoiceIn/front/descriptor/index.js @@ -96,6 +96,20 @@ class Controller extends Descriptor { .then(() => this.$state.reload()) .then(() => this.vnApp.showSuccess(this.$t('InvoiceIn booked'))); } + + showPdfInvoice() { + this.vnReport.show(`InvoiceIns/${this.id}/invoice-in-pdf`); + } + + sendPdfInvoice($data) { + if (!$data.email) + return this.vnApp.showError(this.$t(`The email can't be empty`)); + + return this.vnEmail.send(`InvoiceIns/${this.entity.id}/invoice-in-email`, { + recipient: $data.email, + recipientId: this.entity.supplier.id + }); + } } ngModule.vnComponent('vnInvoiceInDescriptor', { diff --git a/modules/invoiceIn/front/locale/es.yml b/modules/invoiceIn/front/locale/es.yml index 4f36b33fa..1deff32d3 100644 --- a/modules/invoiceIn/front/locale/es.yml +++ b/modules/invoiceIn/front/locale/es.yml @@ -19,3 +19,5 @@ To book: Contabilizar Total amount: Total importe Total net: Total neto Total stems: Total tallos +Show agricultural invoice as PDF: Ver factura agrícola como PDF +Send agricultural invoice as PDF: Enviar factura agrícola como PDF diff --git a/modules/item/back/methods/item-shelving/deleteItemShelvings.js b/modules/item/back/methods/item-shelving/deleteItemShelvings.js new file mode 100644 index 000000000..f534b4e9a --- /dev/null +++ b/modules/item/back/methods/item-shelving/deleteItemShelvings.js @@ -0,0 +1,51 @@ +module.exports = Self => { + Self.remoteMethod('deleteItemShelvings', { + description: 'Deletes the selected item shelvings', + accessType: 'WRITE', + accepts: [{ + arg: 'itemShelvingIds', + type: ['number'], + required: true, + description: 'The itemShelving ids to delete' + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/deleteItemShelvings`, + verb: 'POST' + } + }); + + Self.deleteItemShelvings = async(itemShelvingIds, options) => { + const models = Self.app.models; + const myOptions = {}; + let tx; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const promises = []; + for (let itemShelvingId of itemShelvingIds) { + const itemShelvingToDelete = models.ItemShelving.destroyById(itemShelvingId, myOptions); + promises.push(itemShelvingToDelete); + } + + const deletedItemShelvings = await Promise.all(promises); + + if (tx) await tx.commit(); + + return deletedItemShelvings; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js b/modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js new file mode 100644 index 000000000..b4113d7cf --- /dev/null +++ b/modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js @@ -0,0 +1,21 @@ +const models = require('vn-loopback/server/server').models; + +describe('ItemShelving deleteItemShelvings()', () => { + it('should return the deleted itemShelvings', async() => { + const tx = await models.Order.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const itemShelvingIds = [1, 2]; + const result = await models.ItemShelving.deleteItemShelvings(itemShelvingIds, options); + + expect(result.length).toEqual(2); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/item/back/model-config.json b/modules/item/back/model-config.json index 9737d26fc..40d73f1a6 100644 --- a/modules/item/back/model-config.json +++ b/modules/item/back/model-config.json @@ -53,6 +53,9 @@ "ItemShelvingSale": { "dataSource": "vn" }, + "ItemShelvingPlacementSupplyStock": { + "dataSource": "vn" + }, "ItemImageQueue": { "dataSource": "vn" }, diff --git a/modules/item/back/models/item-shelving-placement-supply.json b/modules/item/back/models/item-shelving-placement-supply.json new file mode 100644 index 000000000..a54013e05 --- /dev/null +++ b/modules/item/back/models/item-shelving-placement-supply.json @@ -0,0 +1,36 @@ +{ + "name": "ItemShelvingPlacementSupplyStock", + "base": "VnModel", + "options": { + "mysql": { + "table": "itemShelvingPlacementSupplyStock" + } + }, + "properties": { + "itemShelvingFk": { + "type": "number", + "id": true + }, + "created": { + "type": "date" + }, + "itemFk": { + "type": "number" + }, + "longName": { + "type": "string" + }, + "parking": { + "type": "string" + }, + "shelving": { + "type": "string" + }, + "packing": { + "type": "number" + }, + "stock": { + "type": "number" + } + } +} \ No newline at end of file diff --git a/modules/item/back/models/item-shelving.js b/modules/item/back/models/item-shelving.js new file mode 100644 index 000000000..5f372a3be --- /dev/null +++ b/modules/item/back/models/item-shelving.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/item-shelving/deleteItemShelvings')(Self); +}; diff --git a/modules/item/front/fixed-price/index.html b/modules/item/front/fixed-price/index.html index 8127a76dc..9498bf96f 100644 --- a/modules/item/front/fixed-price/index.html +++ b/modules/item/front/fixed-price/index.html @@ -23,9 +23,9 @@
- @@ -34,18 +34,18 @@ - - - - + diff --git a/print/templates/reports/invoice/invoice.js b/print/templates/reports/invoice/invoice.js index db94a7a12..31df7f7f5 100755 --- a/print/templates/reports/invoice/invoice.js +++ b/print/templates/reports/invoice/invoice.js @@ -81,7 +81,7 @@ module.exports = { return this.rawSqlFromDef(`taxes`, [reference]); }, fetchIntrastat(reference) { - return this.rawSqlFromDef(`intrastat`, [reference, reference, reference]); + return this.rawSqlFromDef(`intrastat`, [reference, reference, reference, reference]); }, fetchRectified(reference) { return this.rawSqlFromDef(`rectified`, [reference]); diff --git a/print/templates/reports/invoice/locale/en.yml b/print/templates/reports/invoice/locale/en.yml index 4e4688b55..336592f0c 100644 --- a/print/templates/reports/invoice/locale/en.yml +++ b/print/templates/reports/invoice/locale/en.yml @@ -33,4 +33,5 @@ issued: Issued plantPassport: Plant passport observations: Observations wireTransfer: "Pay method: Transferencia" -accountNumber: "Account number: {0}" \ No newline at end of file +accountNumber: "Account number: {0}" +services: Services \ No newline at end of file diff --git a/print/templates/reports/invoice/locale/es.yml b/print/templates/reports/invoice/locale/es.yml index d37e77943..32f6fc708 100644 --- a/print/templates/reports/invoice/locale/es.yml +++ b/print/templates/reports/invoice/locale/es.yml @@ -33,4 +33,5 @@ issued: F. emisión plantPassport: Pasaporte fitosanitario observations: Observaciones wireTransfer: "Forma de pago: Transferencia" -accountNumber: "Número de cuenta: {0}" \ No newline at end of file +accountNumber: "Número de cuenta: {0}" +services: Servicios \ No newline at end of file diff --git a/print/templates/reports/invoice/sql/intrastat.sql b/print/templates/reports/invoice/sql/intrastat.sql index e2ee47667..5cc3ebd7f 100644 --- a/print/templates/reports/invoice/sql/intrastat.sql +++ b/print/templates/reports/invoice/sql/intrastat.sql @@ -1,4 +1,4 @@ -SELECT +(SELECT ir.id code, ir.description description, CAST(SUM(IFNULL(i.stems, 1) * s.quantity) AS DECIMAL(10,2)) stems, @@ -19,4 +19,14 @@ SELECT WHERE t.refFk = ? AND i.intrastatFk GROUP BY i.intrastatFk - ORDER BY i.intrastatFk; \ No newline at end of file + ORDER BY i.intrastatFk) +UNION ALL +(SELECT + NULL AS code, + NULL AS description, + 0 AS stems, + 0 AS netKg, + CAST(SUM((ts.quantity * ts.price)) AS DECIMAL(10,2)) AS subtotal + FROM vn.ticketService ts + JOIN vn.ticket t ON ts.ticketFk = t.id + WHERE t.refFk = ?); \ No newline at end of file diff --git a/print/templates/reports/invoiceIn/assets/css/import.js b/print/templates/reports/invoiceIn/assets/css/import.js new file mode 100644 index 000000000..37a98dfdd --- /dev/null +++ b/print/templates/reports/invoiceIn/assets/css/import.js @@ -0,0 +1,12 @@ +const Stylesheet = require(`vn-print/core/stylesheet`); + +const path = require('path'); +const vnPrintPath = path.resolve('print'); + +module.exports = new Stylesheet([ + `${vnPrintPath}/common/css/spacing.css`, + `${vnPrintPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/layout.css`, + `${vnPrintPath}/common/css/report.css`, + `${__dirname}/style.css`]) + .mergeStyles(); diff --git a/print/templates/reports/invoiceIn/assets/css/style.css b/print/templates/reports/invoiceIn/assets/css/style.css new file mode 100644 index 000000000..9fda2a613 --- /dev/null +++ b/print/templates/reports/invoiceIn/assets/css/style.css @@ -0,0 +1,42 @@ +h2 { + font-weight: 100; + color: #555 +} + +.table-title { + margin-bottom: 15px; + font-size: .8rem +} + +.table-title h2 { + margin: 0 15px 0 0 +} + +.ticket-info { + font-size: 22px +} + + +#nickname h2 { + max-width: 400px; + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; +} + +#phytosanitary { + padding-right: 10px +} + +#phytosanitary .flag img { + width: 100% +} + +#phytosanitary .flag .flag-text { + padding-left: 10px; + box-sizing: border-box; +} + +.phytosanitary-info { + margin-top: 10px +} \ No newline at end of file diff --git a/print/templates/reports/invoiceIn/assets/images/europe.png b/print/templates/reports/invoiceIn/assets/images/europe.png new file mode 100644 index 000000000..673be92ae Binary files /dev/null and b/print/templates/reports/invoiceIn/assets/images/europe.png differ diff --git a/print/templates/reports/invoiceIn/invoiceIn.html b/print/templates/reports/invoiceIn/invoiceIn.html new file mode 100644 index 000000000..8919403b9 --- /dev/null +++ b/print/templates/reports/invoiceIn/invoiceIn.html @@ -0,0 +1,214 @@ + + + +
Item ID + Description Warehouse P.P.U. P.P.P. @@ -170,7 +170,7 @@ - + - \ No newline at end of file + diff --git a/modules/item/front/fixed-price/index.js b/modules/item/front/fixed-price/index.js index b84c2cc2d..89ce0b172 100644 --- a/modules/item/front/fixed-price/index.js +++ b/modules/item/front/fixed-price/index.js @@ -12,14 +12,6 @@ export default class Controller extends Section { }, defaultSearch: true, columns: [ - { - field: 'itemName', - autocomplete: { - url: 'Items', - showField: 'name', - valueField: 'id' - } - }, { field: 'warehouseFk', autocomplete: { @@ -105,8 +97,8 @@ export default class Controller extends Section { exprBuilder(param, value) { switch (param) { - case 'itemName': - return {'i.id': value}; + case 'name': + return {'i.name': {like: `%${value}%`}}; case 'itemFk': case 'warehouseFk': case 'rate2': diff --git a/modules/item/front/index.js b/modules/item/front/index.js index 6a8d1b3b7..d2ffcc8fb 100644 --- a/modules/item/front/index.js +++ b/modules/item/front/index.js @@ -24,3 +24,5 @@ import './waste/detail'; import './fixed-price'; import './fixed-price-search-panel'; import './item-type'; +import './item-shelving'; + diff --git a/modules/item/front/item-shelving/index.html b/modules/item/front/item-shelving/index.html new file mode 100644 index 000000000..fa7a70544 --- /dev/null +++ b/modules/item/front/item-shelving/index.html @@ -0,0 +1,118 @@ + + + + + +
+
+
Total
+ + +
+
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Created + + Item + + Concept + + Parking + + Shelving + + Etiqueta + + Packing +
+ + + {{::itemShelvingPlacementSupplyStock.created | date: 'dd/MM/yyyy'}} + {{::itemShelvingPlacementSupplyStock.itemFk}} + + + {{itemShelvingPlacementSupplyStock.longName}} + + + {{::itemShelvingPlacementSupplyStock.parking}} + + {{::itemShelvingPlacementSupplyStock.shelving}} + + {{(itemShelvingPlacementSupplyStock.stock / itemShelvingPlacementSupplyStock.packing).toFixed(2)}} + + {{::itemShelvingPlacementSupplyStock.packing}} +
+
+
+
+ + + + + \ No newline at end of file diff --git a/modules/item/front/item-shelving/index.js b/modules/item/front/item-shelving/index.js new file mode 100644 index 000000000..b8584039b --- /dev/null +++ b/modules/item/front/item-shelving/index.js @@ -0,0 +1,89 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; + +export default class Controller extends Section { + constructor($element, $) { + super($element, $); + + this.smartTableOptions = { + activeButtons: { + search: true + }, + columns: [ + { + field: 'parking', + autocomplete: { + url: 'Parkings', + showField: 'code', + valueField: 'code' + } + }, + { + field: 'shelving', + autocomplete: { + url: 'Shelvings', + showField: 'code', + valueField: 'code' + } + }, + { + field: 'created', + searchable: false + }, + { + field: 'itemFk', + searchable: false + }, + { + field: 'longName', + searchable: false + } + ] + }; + } + + get checked() { + const itemShelvings = this.$.model.data || []; + const checkedLines = []; + for (let itemShelving of itemShelvings) { + if (itemShelving.checked) + checkedLines.push(itemShelving.itemShelvingFk); + } + + return checkedLines; + } + + calculateTotals() { + this.labelTotal = 0; + const itemShelvings = this.$.model.data || []; + itemShelvings.forEach(itemShelving => { + const label = itemShelving.stock / itemShelving.packing; + this.labelTotal += label; + }); + } + + onRemove() { + const params = {itemShelvingIds: this.checked}; + const query = `ItemShelvings/deleteItemShelvings`; + this.$http.post(query, params) + .then(() => { + this.vnApp.showSuccess(this.$t('ItemShelvings removed')); + this.$.model.refresh(); + }); + } + + exprBuilder(param, value) { + switch (param) { + case 'parking': + case 'shelving': + case 'label': + case 'packing': + return {[param]: value}; + } + } +} + +ngModule.vnComponent('vnItemShelving', { + template: require('./index.html'), + controller: Controller +}); diff --git a/modules/item/front/item-shelving/index.spec.js b/modules/item/front/item-shelving/index.spec.js new file mode 100644 index 000000000..55df1c27d --- /dev/null +++ b/modules/item/front/item-shelving/index.spec.js @@ -0,0 +1,81 @@ +import './index'; +import crudModel from 'core/mocks/crud-model'; + +describe('item shelving', () => { + describe('Component vnItemShelving', () => { + let controller; + let $httpBackend; + + beforeEach(ngModule('item')); + + beforeEach(inject(($componentController, _$httpBackend_) => { + $httpBackend = _$httpBackend_; + const $element = angular.element(''); + controller = $componentController('vnItemShelving', {$element}); + controller.$.model = crudModel; + controller.$.model.data = [ + {itemShelvingFk: 1, packing: 10, stock: 1}, + {itemShelvingFk: 2, packing: 12, stock: 5}, + {itemShelvingFk: 4, packing: 20, stock: 10} + ]; + const modelData = controller.$.model.data; + modelData[0].checked = true; + modelData[1].checked = true; + })); + + describe('checked() getter', () => { + it('should return a the selected rows', () => { + const result = controller.checked; + + expect(result).toEqual(expect.arrayContaining([1, 2])); + }); + }); + + describe('calculateTotals()', () => { + it('should calculate the total of labels', () => { + controller.calculateTotals(); + + expect(controller.labelTotal).toEqual(1.0166666666666666); + }); + }); + + describe('onRemove()', () => { + it('shoud remove the selected lines', () => { + jest.spyOn(controller.$.model, 'refresh'); + const expectedParams = {itemShelvingIds: [1, 2]}; + + $httpBackend.expectPOST('ItemShelvings/deleteItemShelvings', expectedParams).respond(200); + controller.onRemove(); + $httpBackend.flush(); + + expect(controller.$.model.refresh).toHaveBeenCalled(); + }); + }); + + describe('exprBuilder()', () => { + it('should search by parking', () => { + const expr = controller.exprBuilder('parking', '700-01'); + + expect(expr).toEqual({'parking': '700-01'}); + }); + + it('should search by shelving', () => { + const expr = controller.exprBuilder('shelving', 'AAA'); + + expect(expr).toEqual({'shelving': 'AAA'}); + }); + + it('should search by label', () => { + const expr = controller.exprBuilder('label', 0.17); + + expect(expr).toEqual({'label': 0.17}); + }); + + it('should search by packing', () => { + const expr = controller.exprBuilder('packing', 10); + + expect(expr).toEqual({'packing': 10}); + }); + }); + }); +}); diff --git a/modules/item/front/item-shelving/locale/es.yml b/modules/item/front/item-shelving/locale/es.yml new file mode 100644 index 000000000..006363cfa --- /dev/null +++ b/modules/item/front/item-shelving/locale/es.yml @@ -0,0 +1,5 @@ +Shelving: Matrícula +Remove selected lines: Eliminar líneas seleccionadas +Selected lines will be deleted: Las líneas seleccionadas serán eliminadas +ItemShelvings removed: Carros eliminados +Total labels: Total etiquetas \ No newline at end of file diff --git a/modules/item/front/locale/es.yml b/modules/item/front/locale/es.yml index 1b75e3802..88ab031e1 100644 --- a/modules/item/front/locale/es.yml +++ b/modules/item/front/locale/es.yml @@ -54,6 +54,7 @@ Basic data: Datos básicos Tax: IVA History: Historial Botanical: Botánico +Shelvings: Carros Barcodes: Códigos de barras Diary: Histórico Item diary: Registro de compra-venta diff --git a/modules/item/front/routes.json b/modules/item/front/routes.json index 5743d0ce7..3dea69ba1 100644 --- a/modules/item/front/routes.json +++ b/modules/item/front/routes.json @@ -15,11 +15,12 @@ "card": [ {"state": "item.card.basicData", "icon": "settings"}, {"state": "item.card.tags", "icon": "icon-tags"}, + {"state": "item.card.last-entries", "icon": "icon-regentry"}, {"state": "item.card.tax", "icon": "icon-tax"}, - {"state": "item.card.botanical", "icon": "local_florist"}, + {"state": "item.card.botanical", "icon": "local_florist"}, + {"state": "item.card.shelving", "icon": "icon-inventory"}, {"state": "item.card.itemBarcode", "icon": "icon-barcode"}, {"state": "item.card.diary", "icon": "icon-transaction"}, - {"state": "item.card.last-entries", "icon": "icon-regentry"}, {"state": "item.card.log", "icon": "history"} ], "itemType": [ @@ -92,6 +93,16 @@ }, "acl": ["buyer"] }, + { + "url" : "/shelving", + "state": "item.card.shelving", + "component": "vn-item-shelving", + "description": "Shelvings", + "params": { + "item": "$ctrl.item" + }, + "acl": ["employee"] + }, { "url" : "/barcode", "state": "item.card.itemBarcode", diff --git a/modules/monitor/front/index/clients/index.html b/modules/monitor/front/index/clients/index.html index eafc2256e..381c0e1ae 100644 --- a/modules/monitor/front/index/clients/index.html +++ b/modules/monitor/front/index/clients/index.html @@ -19,22 +19,24 @@ - @@ -100,9 +102,9 @@ - - \ No newline at end of file + diff --git a/modules/route/front/routes.json b/modules/route/front/routes.json index f5e7d9ae8..75e1fdc57 100644 --- a/modules/route/front/routes.json +++ b/modules/route/front/routes.json @@ -39,7 +39,7 @@ "abstract": true, "component": "vn-route-card" }, { - "url": "/agency-term", + "url": "/agency-term?q", "abstract": true, "state": "route.agencyTerm", "component": "ui-view" @@ -49,12 +49,12 @@ "component": "vn-agency-term-index", "description": "Autonomous", "acl": ["administrative"] - },{ + },{ "url": "/createInvoiceIn?q", "state": "route.agencyTerm.createInvoiceIn", "component": "vn-agency-term-create-invoice-in", "description": "File management", - "params": { + "params": { "route": "$ctrl.route" }, "acl": ["administrative"] @@ -92,4 +92,4 @@ "acl": ["delivery"] } ] -} \ No newline at end of file +} diff --git a/modules/shelving/front/routes.json b/modules/shelving/front/routes.json index b99ca4cac..09a8e389b 100644 --- a/modules/shelving/front/routes.json +++ b/modules/shelving/front/routes.json @@ -13,9 +13,6 @@ {"state": "shelving.card.log", "icon": "history"} ] }, - "keybindings": [ - {"key": "s", "state": "shelving.index"} - ], "routes": [ { "url": "/shelving", diff --git a/modules/supplier/back/models/supplier.json b/modules/supplier/back/models/supplier.json index b27073ca5..3cd6386a8 100644 --- a/modules/supplier/back/models/supplier.json +++ b/modules/supplier/back/models/supplier.json @@ -51,6 +51,9 @@ "isSerious": { "type": "boolean" }, + "isTrucker": { + "type": "boolean" + }, "note": { "type": "string" }, diff --git a/modules/supplier/front/descriptor/index.js b/modules/supplier/front/descriptor/index.js index df9fe2155..a26d9c510 100644 --- a/modules/supplier/front/descriptor/index.js +++ b/modules/supplier/front/descriptor/index.js @@ -41,6 +41,7 @@ class Controller extends Descriptor { 'payDay', 'isActive', 'isSerious', + 'isTrucker', 'account' ], include: [ diff --git a/modules/supplier/front/descriptor/index.spec.js b/modules/supplier/front/descriptor/index.spec.js index 8926fa4d1..4d16c5183 100644 --- a/modules/supplier/front/descriptor/index.spec.js +++ b/modules/supplier/front/descriptor/index.spec.js @@ -27,6 +27,7 @@ describe('Supplier Component vnSupplierDescriptor', () => { 'payDay', 'isActive', 'isSerious', + 'isTrucker', 'account' ], include: [ diff --git a/modules/supplier/front/fiscal-data/index.html b/modules/supplier/front/fiscal-data/index.html index 4ae07c81a..a3ede2058 100644 --- a/modules/supplier/front/fiscal-data/index.html +++ b/modules/supplier/front/fiscal-data/index.html @@ -118,8 +118,6 @@ rule vn-focus> - - + + - - {{name}} ({{country.country}}) + + + + diff --git a/modules/supplier/front/fiscal-data/locale/es.yml b/modules/supplier/front/fiscal-data/locale/es.yml index 4cb537198..5232dd95d 100644 --- a/modules/supplier/front/fiscal-data/locale/es.yml +++ b/modules/supplier/front/fiscal-data/locale/es.yml @@ -3,3 +3,4 @@ Sage transaction type: Tipo de transacción Sage Sage withholding: Retención Sage Supplier activity: Actividad proveedor Healt register: Pasaporte sanitario +Trucker: Transportista \ No newline at end of file diff --git a/modules/ticket/back/methods/expedition/deleteExpeditions.js b/modules/ticket/back/methods/expedition/deleteExpeditions.js new file mode 100644 index 000000000..2419d3a5e --- /dev/null +++ b/modules/ticket/back/methods/expedition/deleteExpeditions.js @@ -0,0 +1,52 @@ + +module.exports = Self => { + Self.remoteMethod('deleteExpeditions', { + description: 'Delete the selected expeditions', + accessType: 'WRITE', + accepts: [{ + arg: 'expeditionIds', + type: ['number'], + required: true, + description: 'The expeditions ids to delete' + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/deleteExpeditions`, + verb: 'POST' + } + }); + + Self.deleteExpeditions = async(expeditionIds, options) => { + const models = Self.app.models; + const myOptions = {}; + let tx; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const promises = []; + for (let expeditionId of expeditionIds) { + const deletedExpedition = models.Expedition.destroyById(expeditionId, myOptions); + promises.push(deletedExpedition); + } + + const deletedExpeditions = await Promise.all(promises); + + if (tx) await tx.commit(); + + return deletedExpeditions; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/ticket/back/methods/expedition/moveExpeditions.js b/modules/ticket/back/methods/expedition/moveExpeditions.js new file mode 100644 index 000000000..cef35ab86 --- /dev/null +++ b/modules/ticket/back/methods/expedition/moveExpeditions.js @@ -0,0 +1,93 @@ +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethodCtx('moveExpeditions', { + description: 'Move the selected expeditions to another ticket', + accessType: 'WRITE', + accepts: [{ + arg: 'clientId', + type: 'number', + description: `The client id`, + required: true + }, + { + arg: 'landed', + type: 'date', + description: `The landing date` + }, + { + arg: 'warehouseId', + type: 'number', + description: `The warehouse id`, + required: true + }, + { + arg: 'addressId', + type: 'number', + description: `The address id`, + required: true + }, + { + arg: 'agencyModeId', + type: 'any', + description: `The agencyMode id` + }, + { + arg: 'routeId', + type: 'any', + description: `The route id` + }, + { + arg: 'expeditionIds', + type: ['number'], + required: true, + description: 'The expeditions ids to move' + }], + returns: { + type: 'object', + root: true + }, + http: { + path: `/moveExpeditions`, + verb: 'POST' + } + }); + + Self.moveExpeditions = async(ctx, options) => { + const models = Self.app.models; + const args = ctx.args; + const myOptions = {}; + let tx; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + if (args.routeId) { + const route = await models.Route.findById(args.routeId, null, myOptions); + if (!route) throw new UserError('This route does not exists'); + } + const ticket = await models.Ticket.new(ctx, myOptions); + const promises = []; + for (let expeditionsId of args.expeditionIds) { + const expeditionToUpdate = await models.Expedition.findById(expeditionsId, null, myOptions); + const expeditionUpdated = expeditionToUpdate.updateAttribute('ticketFk', ticket.id, myOptions); + promises.push(expeditionUpdated); + } + + await Promise.all(promises); + + if (tx) await tx.commit(); + + return ticket; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js new file mode 100644 index 000000000..14bdf7aea --- /dev/null +++ b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js @@ -0,0 +1,22 @@ +const models = require('vn-loopback/server/server').models; + +describe('ticket deleteExpeditions()', () => { + it('should delete the selected expeditions', async() => { + const tx = await models.Expedition.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const expeditionIds = [12, 13]; + const result = await models.Expedition.deleteExpeditions(expeditionIds, options); + + expect(result.length).toEqual(2); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); + diff --git a/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js b/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js new file mode 100644 index 000000000..67919e76c --- /dev/null +++ b/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js @@ -0,0 +1,39 @@ +const models = require('vn-loopback/server/server').models; + +describe('ticket moveExpeditions()', () => { + it('should move the selected expeditions to new ticket', async() => { + const tx = await models.Expedition.beginTransaction({}); + const ctx = { + req: {accessToken: {userId: 9}}, + args: {}, + params: {} + }; + const myCtx = Object.assign({}, ctx); + + try { + const options = {transaction: tx}; + myCtx.args = { + clientId: 1101, + landed: new Date(), + warehouseId: 1, + addressId: 121, + agencyModeId: 1, + routeId: null, + expeditionIds: [1, 2] + + }; + + const ticket = await models.Expedition.moveExpeditions(myCtx, options); + + const newestTicketIdInFixtures = 27; + + expect(ticket.id).toBeGreaterThan(newestTicketIdInFixtures); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); + diff --git a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js index e76511421..51cd2403f 100644 --- a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js +++ b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js @@ -79,10 +79,18 @@ describe('sale updatePrice()', () => { const price = 5.4; const originalSalesPersonMana = await models.WorkerMana.findById(18, null, options); const manaComponent = await models.Component.findOne({where: {code: 'mana'}}, options); + const teamOne = 96; + const userId = ctx.req.accessToken.userId; + + const business = await models.Business.findOne({where: {workerFk: userId}}, options); + await business.updateAttribute('departmentFk', teamOne, options); await models.Sale.updatePrice(ctx, saleId, price, options); const updatedSale = await models.Sale.findById(saleId, null, options); - createdSaleComponent = await models.SaleComponent.findOne({where: {saleFk: saleId, componentFk: manaComponent.id}}, options); + const createdSaleComponent = await models.SaleComponent.findOne({ + where: { + saleFk: saleId, componentFk: manaComponent.id + }}, options); expect(updatedSale.price).toBe(price); expect(createdSaleComponent.value).toEqual(-2.04); diff --git a/modules/ticket/back/methods/sale/specs/usesMana.spec.js b/modules/ticket/back/methods/sale/specs/usesMana.spec.js new file mode 100644 index 000000000..777bdc8f0 --- /dev/null +++ b/modules/ticket/back/methods/sale/specs/usesMana.spec.js @@ -0,0 +1,48 @@ +const models = require('vn-loopback/server/server').models; + +describe('sale usesMana()', () => { + const ctx = { + req: { + accessToken: {userId: 18} + } + }; + + it('should return that the worker uses mana', async() => { + const tx = await models.Sale.beginTransaction({}); + + try { + const options = {transaction: tx}; + const teamOne = 96; + const userId = ctx.req.accessToken.userId; + + const business = await models.Business.findOne({where: {workerFk: userId}}, options); + await business.updateAttribute('departmentFk', teamOne, options); + + const usesMana = await models.Sale.usesMana(ctx, options); + + expect(usesMana).toBe(true); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return that the worker not uses mana', async() => { + const tx = await models.Sale.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const usesMana = await models.Sale.usesMana(ctx, options); + + expect(usesMana).toBe(false); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/ticket/back/methods/sale/updatePrice.js b/modules/ticket/back/methods/sale/updatePrice.js index bbd9d154d..302522cfb 100644 --- a/modules/ticket/back/methods/sale/updatePrice.js +++ b/modules/ticket/back/methods/sale/updatePrice.js @@ -77,7 +77,8 @@ module.exports = Self => { const oldPrice = sale.price; const userId = ctx.req.accessToken.userId; - const usesMana = await models.WorkerMana.findOne({where: {workerFk: userId}, fields: 'amount'}, myOptions); + + const usesMana = await models.Sale.usesMana(ctx, myOptions); const componentCode = usesMana ? 'mana' : 'buyerDiscount'; const discount = await models.Component.findOne({where: {code: componentCode}}, myOptions); const componentId = discount.id; @@ -88,7 +89,6 @@ module.exports = Self => { saleFk: id }; const saleComponent = await models.SaleComponent.findOne({where}, myOptions); - if (saleComponent) { await models.SaleComponent.updateAll(where, { value: saleComponent.value + componentValue diff --git a/modules/ticket/back/methods/sale/usesMana.js b/modules/ticket/back/methods/sale/usesMana.js new file mode 100644 index 000000000..093057dca --- /dev/null +++ b/modules/ticket/back/methods/sale/usesMana.js @@ -0,0 +1,31 @@ +module.exports = Self => { + Self.remoteMethodCtx('usesMana', { + description: 'Returns if the worker uses mana', + accessType: 'READ', + accepts: [], + returns: { + type: 'boolean', + root: true + }, + http: { + path: `/usesMana`, + verb: 'GET' + } + }); + + Self.usesMana = async(ctx, options) => { + const models = Self.app.models; + const userId = ctx.req.accessToken.userId; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const salesDepartment = await models.Department.findOne({where: {code: 'VT'}, fields: 'id'}, myOptions); + const departments = await models.Department.getLeaves(salesDepartment.id, null, myOptions); + const workerDepartment = await models.WorkerDepartment.findById(userId, null, myOptions); + const usesMana = departments.find(department => department.id == workerDepartment.departmentFk); + + return usesMana ? true : false; + }; +}; diff --git a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js index 2aa2a07c4..b3291c25a 100644 --- a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js +++ b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js @@ -18,9 +18,12 @@ describe('ticket componentUpdate()', () => { beforeAll(async() => { const deliveryComponenet = await models.Component.findOne({where: {code: 'delivery'}}); deliveryComponentId = deliveryComponenet.id; - componentOfSaleSeven = `SELECT value FROM vn.saleComponent WHERE saleFk = 7 AND componentFk = ${deliveryComponentId}`; - componentOfSaleEight = `SELECT value FROM vn.saleComponent WHERE saleFk = 8 AND componentFk = ${deliveryComponentId}`; - + componentOfSaleSeven = `SELECT value + FROM vn.saleComponent + WHERE saleFk = 7 AND componentFk = ${deliveryComponentId}`; + componentOfSaleEight = `SELECT value + FROM vn.saleComponent + WHERE saleFk = 8 AND componentFk = ${deliveryComponentId}`; [componentValue] = await models.SaleComponent.rawSql(componentOfSaleSeven); firstvalueBeforeChange = componentValue.value; diff --git a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js index 1873207aa..1f6712087 100644 --- a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js +++ b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js @@ -110,6 +110,11 @@ describe('sale updateDiscount()', () => { const componentId = manaDiscount.id; const manaCode = 'mana'; + const teamOne = 96; + const userId = ctx.req.accessToken.userId; + const business = await models.Business.findOne({where: {workerFk: userId}}, options); + await business.updateAttribute('departmentFk', teamOne, options); + await models.Ticket.updateDiscount(ctx, ticketId, sales, newDiscount, manaCode, options); const updatedSale = await models.Sale.findById(originalSaleId, null, options); @@ -150,6 +155,11 @@ describe('sale updateDiscount()', () => { const componentId = manaDiscount.id; const manaCode = 'manaClaim'; + const teamOne = 96; + const userId = ctx.req.accessToken.userId; + const business = await models.Business.findOne({where: {workerFk: userId}}, options); + await business.updateAttribute('departmentFk', teamOne, options); + await models.Ticket.updateDiscount(ctx, ticketId, sales, newDiscount, manaCode, options); const updatedSale = await models.Sale.findById(originalSaleId, null, options); diff --git a/modules/ticket/back/methods/ticket/updateDiscount.js b/modules/ticket/back/methods/ticket/updateDiscount.js index b1291a45b..9e9fdb664 100644 --- a/modules/ticket/back/methods/ticket/updateDiscount.js +++ b/modules/ticket/back/methods/ticket/updateDiscount.js @@ -98,12 +98,7 @@ module.exports = Self => { if (isLocked || (!hasAllowedRoles && alertLevel > 0)) throw new UserError(`The sales of this ticket can't be modified`); - const usesMana = await models.WorkerMana.findOne({ - where: { - workerFk: userId - }, - fields: 'amount'}, myOptions); - + const usesMana = await models.Sale.usesMana(ctx, myOptions); const componentCode = usesMana ? manaCode : 'buyerDiscount'; const discountComponent = await models.Component.findOne({ where: {code: componentCode}}, myOptions); @@ -115,14 +110,38 @@ module.exports = Self => { for (let sale of sales) { const oldDiscount = sale.discount; const value = ((-sale.price * newDiscount) / 100); - const newComponent = models.SaleComponent.upsert({ - saleFk: sale.id, - value: value, - componentFk: componentId}, myOptions); + + const manaComponent = await models.Component.findOne({ + where: {code: 'mana'} + }, myOptions); + + const manaClaimComponent = await models.Component.findOne({ + where: {code: 'manaClaim'} + }, myOptions); + + const [oldComponent] = await models.SaleComponent.find({ + where: { + and: [ + {saleFk: sale.id}, + {componentFk: {inq: [manaComponent.id, manaClaimComponent.id]}} + ] + } + }, myOptions); + + let deletedComponent; + if (oldComponent) { + const filter = { + saleFk: sale.id, + componentFk: oldComponent.componentFk + }; + deletedComponent = await models.SaleComponent.destroyAll(filter, myOptions); + } + + const newComponent = await createSaleComponent(sale.id, value, componentId, myOptions); const updatedSale = sale.updateAttribute('discount', newDiscount, myOptions); - promises.push(newComponent, updatedSale); + promises.push(newComponent, updatedSale, deletedComponent); const change = `${oldDiscount}% ➔ *${newDiscount}%*`; changesMade += `\r\n-${sale.itemFk}: ${sale.concept} (${sale.quantity}) ${change}`; @@ -165,4 +184,14 @@ module.exports = Self => { throw e; } }; + + async function createSaleComponent(saleId, value, componentId, myOptions) { + const models = Self.app.models; + + return models.SaleComponent.create({ + saleFk: saleId, + value: value, + componentFk: componentId + }, myOptions); + } }; diff --git a/modules/ticket/back/models/expedition.js b/modules/ticket/back/models/expedition.js index 9d6564373..46cde6890 100644 --- a/modules/ticket/back/models/expedition.js +++ b/modules/ticket/back/models/expedition.js @@ -1,3 +1,5 @@ module.exports = function(Self) { require('../methods/expedition/filter')(Self); + require('../methods/expedition/deleteExpeditions')(Self); + require('../methods/expedition/moveExpeditions')(Self); }; diff --git a/modules/ticket/back/models/sale.js b/modules/ticket/back/models/sale.js index 2a4457263..ae247fc24 100644 --- a/modules/ticket/back/models/sale.js +++ b/modules/ticket/back/models/sale.js @@ -8,6 +8,7 @@ module.exports = Self => { require('../methods/sale/recalculatePrice')(Self); require('../methods/sale/refund')(Self); require('../methods/sale/canEdit')(Self); + require('../methods/sale/usesMana')(Self); Self.validatesPresenceOf('concept', { message: `Concept cannot be blank` diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index a41d368f6..ec6dc7ee2 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -8,54 +8,77 @@ auto-load="true"> - - - - - - Expedition - Item - Name - Package type - Counter - externalId - Created - State - - - - - - - - - - {{expedition.id | zeroFill:6}} - - - {{expedition.packagingFk}} - - - {{::expedition.packageItemName}} - {{::expedition.freightItemName}} - {{::expedition.counter}} - {{::expedition.externalId}} - {{::expedition.created | date:'dd/MM/yyyy HH:mm'}} - {{::expedition.state}} - - - - - - - + + + + + + + + + +

Subtotal {{$ctrl.ticket.totalWithoutVat | currency: 'EUR':2}}

+

VAT {{$ctrl.ticket.totalWithVat - $ctrl.ticket.totalWithoutVat | currency: 'EUR':2}}

+

Total {{$ctrl.ticket.totalWithVat | currency: 'EUR':2}}

+
+
+ + + + + + + + Expedition + Item + Name + Package type + Counter + externalId + Created + State + + + + + + + + + + {{expedition.id | zeroFill:6}} + + + {{expedition.packagingFk}} + + + {{::expedition.packageItemName}} + {{::expedition.freightItemName}} + {{::expedition.counter}} + {{::expedition.externalId}} + {{::expedition.created | date:'dd/MM/yyyy HH:mm'}} + {{::expedition.state}} + + + + + + +
- + on-accept="$ctrl.onRemove()"> - + - + State @@ -111,4 +134,37 @@ - \ No newline at end of file + + + + + New ticket without route + + + New ticket with route + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/ticket/front/expedition/index.js b/modules/ticket/front/expedition/index.js index 120d89bb2..7ffe2fe5e 100644 --- a/modules/ticket/front/expedition/index.js +++ b/modules/ticket/front/expedition/index.js @@ -2,6 +2,27 @@ import ngModule from '../module'; import Section from 'salix/components/section'; class Controller extends Section { + constructor($element, $scope) { + super($element, $scope); + this.landed = new Date(); + this.newRoute = null; + } + + get checked() { + const rows = this.$.model.data || []; + const checkedRows = []; + for (let row of rows) { + if (row.checked) + checkedRows.push(row.id); + } + + return checkedRows; + } + + get totalChecked() { + return this.checked.length; + } + onDialogAccept(id) { return this.$http.delete(`Expeditions/${id}`) .then(() => this.$.model.refresh()); @@ -11,6 +32,33 @@ class Controller extends Section { this.expedition = expedition; this.$.statusLog.show(); } + + onRemove() { + const params = {expeditionIds: this.checked}; + const query = `Expeditions/deleteExpeditions`; + this.$http.post(query, params) + .then(() => { + this.vnApp.showSuccess(this.$t('Expedition removed')); + this.$.model.refresh(); + }); + } + + createTicket(landed, routeFk) { + const params = { + clientId: this.ticket.clientFk, + landed: landed, + warehouseId: this.ticket.warehouseFk, + addressId: this.ticket.addressFk, + agencyModeId: this.ticket.agencyModeFk, + routeId: routeFk, + expeditionIds: this.checked + }; + const query = `Expeditions/moveExpeditions`; + this.$http.post(query, params).then(res => { + this.vnApp.showSuccess(this.$t('Data saved!')); + this.$state.go('ticket.card.summary', {id: res.data.id}); + }); + } } ngModule.vnComponent('vnTicketExpedition', { diff --git a/modules/ticket/front/expedition/index.spec.js b/modules/ticket/front/expedition/index.spec.js index 586ef2109..b95d64fa3 100644 --- a/modules/ticket/front/expedition/index.spec.js +++ b/modules/ticket/front/expedition/index.spec.js @@ -17,6 +17,14 @@ describe('Ticket', () => { refresh: () => {} }; controller = $componentController('vnTicketExpedition', {$element: null, $scope}); + controller.$.model.data = [ + {id: 1}, + {id: 2}, + {id: 3} + ]; + const modelData = controller.$.model.data; + modelData[0].checked = true; + modelData[1].checked = true; })); describe('onDialogAccept()', () => { @@ -50,5 +58,51 @@ describe('Ticket', () => { expect(controller.$.statusLog.show).toHaveBeenCalledWith(); }); }); + + describe('onRemove()', () => { + it('should make a query and then call to the model refresh() method', () => { + jest.spyOn($scope.model, 'refresh'); + + const expectedParams = {expeditionIds: [1, 2]}; + $httpBackend.expect('POST', 'Expeditions/deleteExpeditions', expectedParams).respond(200); + controller.onRemove(); + $httpBackend.flush(); + + expect($scope.model.refresh).toHaveBeenCalledWith(); + }); + }); + + describe('createTicket()', () => { + it('should make a query and then call to the $state go() method', () => { + jest.spyOn(controller.$state, 'go').mockReturnThis(); + + const ticket = { + clientFk: 1101, + landed: new Date(), + addressFk: 121, + agencyModeFk: 1, + warehouseFk: 1 + }; + const routeId = null; + controller.ticket = ticket; + + const ticketToTransfer = {id: 28}; + + const expectedParams = { + clientId: 1101, + landed: new Date(), + warehouseId: 1, + addressId: 121, + agencyModeId: 1, + routeId: null, + expeditionIds: [1, 2] + }; + $httpBackend.expect('POST', 'Expeditions/moveExpeditions', expectedParams).respond(ticketToTransfer); + controller.createTicket(ticket.landed, routeId); + $httpBackend.flush(); + + expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.summary', {id: ticketToTransfer.id}); + }); + }); }); }); diff --git a/modules/ticket/front/expedition/locale/es.yml b/modules/ticket/front/expedition/locale/es.yml index d23cf25af..278dcc8f2 100644 --- a/modules/ticket/front/expedition/locale/es.yml +++ b/modules/ticket/front/expedition/locale/es.yml @@ -1 +1,6 @@ -Status log: Hitorial de estados \ No newline at end of file +Status log: Hitorial de estados +Expedition removed: Expedición eliminada +Move: Mover +New ticket without route: Nuevo ticket sin ruta +New ticket with route: Nuevo ticket con ruta +Route id: Id ruta \ No newline at end of file diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html index 42eb10cb0..c624b1a95 100644 --- a/modules/ticket/front/sale/index.html +++ b/modules/ticket/front/sale/index.html @@ -244,7 +244,7 @@
-
MANÁ: {{::$ctrl.edit.mana | currency: 'EUR': 0}}
+
Mana: {{::$ctrl.edit.mana | currency: 'EUR': 0}}
- - - - - -
- - -
-
-
Mana: {{::$ctrl.edit.mana | currency: 'EUR':0}}
-
-
- - - - - - - - -
-

New price

-

- {{$ctrl.getNewPrice() | currency: 'EUR': 2}} -

-
-
-
- - - + + +
+
+
Mana: {{::$ctrl.edit.mana | currency: 'EUR': 0}}
+
- + + + + + + +
+

New price

+

+ {{$ctrl.getNewPrice() | currency: 'EUR': 2}} +

+
-
- Mana: {{::$ctrl.edit.mana | currency: 'EUR': 0}} -
- - + + + + + + +
+
@@ -490,7 +474,7 @@ + ng-click="$ctrl.showEditDiscountPopover($event, sale)"> Update discount { + this.useMana = res.data; + }); + } + /** * Returns checked instances * @@ -243,26 +251,21 @@ class Controller extends Section { showEditDiscountPopover(event, sale) { if (this.isLocked) return; - - this.edit = { - discount: sale.discount, - sale: sale - }; + if (sale) { + this.edit = { + discount: sale.discount, + sale: sale + }; + } else { + this.edit = { + discount: null, + sales: this.selectedValidSales() + }; + } this.$.editDiscount.show(event); } - showEditDiscountDialog(event) { - if (this.isLocked) return; - - this.edit = { - discount: null, - sales: this.selectedValidSales() - }; - - this.$.editDiscountDialog.show(event); - } - changeDiscount() { const sale = this.edit.sale; const newDiscount = this.edit.discount; @@ -278,11 +281,10 @@ class Controller extends Section { const hasChanges = sales.some(sale => { return sale.discount != newDiscount; }); - if (newDiscount != null && hasChanges) this.updateDiscount(sales); - this.$.editDiscountDialog.hide(); + this.$.editDiscount.hide(); } updateDiscount(sales) { @@ -303,7 +305,7 @@ class Controller extends Section { } getNewPrice() { - if (this.edit) { + if (this.edit.sale) { const sale = this.edit.sale; let newDiscount = sale.discount; let newPrice = this.edit.price || sale.price; @@ -505,7 +507,8 @@ class Controller extends Section { } save() { - this.changeDiscount(); + if (this.edit.sale) this.changeDiscount(); + if (this.edit.sales) this.changeMultipleDiscount(); } cancel() { diff --git a/modules/ticket/front/sale/index.spec.js b/modules/ticket/front/sale/index.spec.js index 28d874932..fbee966fd 100644 --- a/modules/ticket/front/sale/index.spec.js +++ b/modules/ticket/front/sale/index.spec.js @@ -115,6 +115,7 @@ describe('Ticket', () => { const expectedAmount = 250; $httpBackend.expect('GET', 'Tickets/1/getSalesPersonMana').respond(200, expectedAmount); + $httpBackend.expect('GET', 'Sales/usesMana').respond(200); $httpBackend.expect('GET', 'WorkerManas/getCurrentWorkerMana').respond(200, expectedAmount); controller.getMana(); $httpBackend.flush(); @@ -393,7 +394,7 @@ describe('Ticket', () => { secondSelectedSale.checked = true; const expectedSales = [firstSelectedSale, secondSelectedSale]; - controller.$.editDiscountDialog = {hide: jest.fn()}; + controller.$.editDiscount = {hide: jest.fn()}; controller.edit = { discount: 10, sales: expectedSales @@ -402,7 +403,7 @@ describe('Ticket', () => { controller.changeMultipleDiscount(); expect(controller.updateDiscount).toHaveBeenCalledWith(expectedSales); - expect(controller.$.editDiscountDialog.hide).toHaveBeenCalledWith(); + expect(controller.$.editDiscount.hide).toHaveBeenCalledWith(); }); it('should not call to the updateDiscount() method and then to the editDiscountDialog hide() method', () => { @@ -417,7 +418,7 @@ describe('Ticket', () => { secondSelectedSale.discount = 10; const expectedSales = [firstSelectedSale, secondSelectedSale]; - controller.$.editDiscountDialog = {hide: jest.fn()}; + controller.$.editDiscount = {hide: jest.fn()}; controller.edit = { discount: 10, sales: expectedSales @@ -426,7 +427,7 @@ describe('Ticket', () => { controller.changeMultipleDiscount(); expect(controller.updateDiscount).not.toHaveBeenCalledWith(expectedSales); - expect(controller.$.editDiscountDialog.hide).toHaveBeenCalledWith(); + expect(controller.$.editDiscount.hide).toHaveBeenCalledWith(); }); }); diff --git a/print/templates/email/delivery-note-link/locale/pt.yml b/print/templates/email/delivery-note-link/locale/pt.yml index 1aab4b6d8..9a70fc4cd 100644 --- a/print/templates/email/delivery-note-link/locale/pt.yml +++ b/print/templates/email/delivery-note-link/locale/pt.yml @@ -7,4 +7,4 @@ copyLink: 'Como alternativa, podes copiar o siguinte link no teu navegador:' poll: Si o deseja, podes responder nosso questionário de satiscação para ajudar-nos a prestar-vos um melhor serviço. Tua opinião é muito importante para nós! help: Cualquer dúvida que surja, no hesites em consultar-la, Estamos aqui para atender-te! -conclusion: Obrigado por tua atenção! \ No newline at end of file +conclusion: Obrigado por tua atenção! diff --git a/print/templates/email/invoiceIn/assets/css/import.js b/print/templates/email/invoiceIn/assets/css/import.js new file mode 100644 index 000000000..4b4bb7086 --- /dev/null +++ b/print/templates/email/invoiceIn/assets/css/import.js @@ -0,0 +1,11 @@ +const Stylesheet = require(`vn-print/core/stylesheet`); + +const path = require('path'); +const vnPrintPath = path.resolve('print'); + +module.exports = new Stylesheet([ + `${vnPrintPath}/common/css/spacing.css`, + `${vnPrintPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/layout.css`, + `${vnPrintPath}/common/css/email.css`]) + .mergeStyles(); diff --git a/print/templates/email/invoiceIn/attachments.json b/print/templates/email/invoiceIn/attachments.json new file mode 100644 index 000000000..cd23d3f92 --- /dev/null +++ b/print/templates/email/invoiceIn/attachments.json @@ -0,0 +1,6 @@ +[ + { + "filename": "invoiceIn.pdf", + "component": "invoiceIn" + } +] diff --git a/print/templates/email/invoiceIn/invoiceIn.html b/print/templates/email/invoiceIn/invoiceIn.html new file mode 100644 index 000000000..65453ccd6 --- /dev/null +++ b/print/templates/email/invoiceIn/invoiceIn.html @@ -0,0 +1,47 @@ + + + + + + {{ $t('subject') }} + + + + + + + + +
+ +
+
+
+ +
+
+ +
+
+ +
+
+

{{ $t('title') }}

+

{{$t('dear')}},

+

+

+
+
+ +
+
+ +
+
+ +
+
+
+
+ + diff --git a/print/templates/email/invoiceIn/invoiceIn.js b/print/templates/email/invoiceIn/invoiceIn.js new file mode 100755 index 000000000..f7a472eb2 --- /dev/null +++ b/print/templates/email/invoiceIn/invoiceIn.js @@ -0,0 +1,11 @@ +const Component = require(`vn-print/core/component`); +const emailHeader = new Component('email-header'); +const emailFooter = new Component('email-footer'); + +module.exports = { + name: 'invoiceIn', + components: { + 'email-header': emailHeader.build(), + 'email-footer': emailFooter.build() + } +}; diff --git a/print/templates/email/invoiceIn/locale/en.yml b/print/templates/email/invoiceIn/locale/en.yml new file mode 100644 index 000000000..47ebc3966 --- /dev/null +++ b/print/templates/email/invoiceIn/locale/en.yml @@ -0,0 +1,5 @@ +subject: Your agricultural invoice +title: Your agricultural invoice +dear: Dear supplier +description: Attached you can find agricultural receipt generated from your last deliveries. Please return a signed and stamped copy to our administration department. +conclusion: Thanks for your attention! diff --git a/print/templates/email/invoiceIn/locale/es.yml b/print/templates/email/invoiceIn/locale/es.yml new file mode 100644 index 000000000..2698763cf --- /dev/null +++ b/print/templates/email/invoiceIn/locale/es.yml @@ -0,0 +1,5 @@ +subject: Tu factura agrícola +title: Tu factura agrícola +dear: Estimado proveedor +description: Adjunto puede encontrar recibo agrícola generado de sus últimas entregas. Por favor, devuelva una copia firmada y sellada a nuestro de departamento de administración. +conclusion: ¡Gracias por tu atención! diff --git a/print/templates/email/invoiceIn/locale/fr.yml b/print/templates/email/invoiceIn/locale/fr.yml new file mode 100644 index 000000000..1c38f3c25 --- /dev/null +++ b/print/templates/email/invoiceIn/locale/fr.yml @@ -0,0 +1,5 @@ +subject: Votre facture agricole +title: Votre facture agricole +dear: Cher Fournisseur +description: Vous trouverez en pièce jointe le reçu agricole généré à partir de vos dernières livraisons. Veuillez retourner une copie signée et tamponnée à notre service administratif. +conclusion: Merci pour votre attention! diff --git a/print/templates/email/invoiceIn/locale/pt.yml b/print/templates/email/invoiceIn/locale/pt.yml new file mode 100644 index 000000000..a43e3a79d --- /dev/null +++ b/print/templates/email/invoiceIn/locale/pt.yml @@ -0,0 +1,5 @@ +subject: A sua fatura agrícola +title: A sua fatura agrícola +dear: Caro Fornecedor +description: Em anexo encontra-se o recibo agrícola gerado a partir das suas últimas entregas. Por favor, devolva uma cópia assinada e carimbada ao nosso departamento de administração. +conclusion: Obrigado pela atenção. diff --git a/print/templates/reports/delivery-note/assets/css/style.css b/print/templates/reports/delivery-note/assets/css/style.css index f99c385fa..8405ae78d 100644 --- a/print/templates/reports/delivery-note/assets/css/style.css +++ b/print/templates/reports/delivery-note/assets/css/style.css @@ -37,4 +37,9 @@ h2 { .phytosanitary-info { margin-top: 10px +} + +.observations{ + text-align: justify; + text-justify: inter-word; } \ No newline at end of file diff --git a/print/templates/reports/delivery-note/delivery-note.html b/print/templates/reports/delivery-note/delivery-note.html index d166f3307..a07c851aa 100644 --- a/print/templates/reports/delivery-note/delivery-note.html +++ b/print/templates/reports/delivery-note/delivery-note.html @@ -1,293 +1,304 @@ - - - - - + + +
- - - - -
-
-
-
-
-

{{$t(deliverNoteType)}}

- - - - - - - - - - - - - - - - - - - -
{{$t('clientId')}}{{client.id}}
{{$t(deliverNoteType)}}{{ticket.id}}
{{$t('date')}}{{ticket.shipped | date('%d-%m-%Y')}}
{{$t('packages')}}{{ticket.packages}}
-
-
-
-
-
{{$t('deliveryAddress')}}
-
-

{{address.nickname}}

-
- {{address.street}} -
-
- {{address.postalCode}}, {{address.city}} ({{address.province}}) -
-
-
- -
-
{{$t('fiscalData')}}
-
-
- {{client.socialName}} -
-
- {{client.street}} -
-
- {{client.fi}} -
-
-
-
-
- - -

{{$t('saleLines')}}

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{{$t('reference')}}{{$t('quantity')}}{{$t('concept')}}{{$t('price')}}{{$t('discount')}}{{$t('vat')}}{{$t('amount')}}
{{sale.itemFk | zerofill('000000')}}{{sale.quantity}}{{sale.concept}}{{sale.price | currency('EUR', $i18n.locale)}}{{(sale.discount / 100) | percentage}}{{sale.vatType}}{{sale.price * sale.quantity * (1 - sale.discount / 100) | currency('EUR', $i18n.locale)}}
- - {{sale.tag5}} {{sale.value5}} - - - {{sale.tag6}} {{sale.value6}} - - - {{sale.tag7}} {{sale.value7}} - -
- {{$t('subtotal')}} - {{getSubTotal() | currency('EUR', $i18n.locale)}}
- - -
- -
-

{{$t('services.title')}}

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{{$t('services.theader.quantity')}}{{$t('services.theader.concept')}}{{$t('services.theader.price')}}{{$t('services.theader.vat')}}{{$t('services.theader.amount')}}
{{service.quantity}}{{service.description}}{{service.price | currency('EUR', $i18n.locale)}}{{service.taxDescription}}{{service.price | currency('EUR', $i18n.locale)}}
- {{$t('services.tfoot.subtotal')}} - {{serviceTotal | currency('EUR', $i18n.locale)}}
- * {{ $t('services.warning') }} -
- -
-
- -
-

{{$t('packagings.title')}}

- - - - - - - - - - - - - - - -
{{$t('packagings.theader.reference')}}{{$t('packagings.theader.quantity')}}{{$t('packagings.theader.concept')}}
{{packaging.itemFk | zerofill('000000')}}{{packaging.quantity}}{{packaging.name}}
-
- -
-
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{{$t('taxes.title')}}
{{$t('taxes.theader.type')}}{{$t('taxes.theader.taxBase')}}{{$t('taxes.theader.tax')}}{{$t('taxes.theader.fee')}}
{{tax.name}} - {{tax.Base | currency('EUR', $i18n.locale)}} - {{tax.vatPercent | percentage}}{{tax.tax | currency('EUR', $i18n.locale)}}
{{$t('subtotal')}} - {{getTotalBase() | currency('EUR', $i18n.locale)}} - {{getTotalTax()| currency('EUR', $i18n.locale)}}
{{$t('total')}}{{getTotal() | currency('EUR', $i18n.locale)}}
-
- - -
-
-
-
-
-
- -
-
- {{$t('plantPassport')}}
-
-
-
-
-
- A - {{getBotanical()}} -
-
- B - ES17462130 -
-
- C - {{ticket.id}} -
-
- D - ES -
-
-
-
+ + + + + - - -
+ + + + +
+
+
+
+
+

{{$t(deliverNoteType)}}

+ + + + + + + + + + + + + + + + + + + +
{{$t('clientId')}}{{client.id}}
{{$t(deliverNoteType)}}{{ticket.id}}
{{$t('date')}}{{ticket.shipped | date('%d-%m-%Y')}}
{{$t('packages')}}{{ticket.packages}}
-
-
- -
-
-
{{$t('digitalSignature')}}
-
- -
{{signature.created | date('%d-%m-%Y')}}
+
+
+
{{$t('deliveryAddress')}}
+
+

{{address.nickname}}

+
+ {{address.street}} +
+
+ {{address.postalCode}}, {{address.city}} ({{address.province}})
- + +
+
{{$t('fiscalData')}}
+
+
+ {{client.socialName}} +
+
+ {{client.street}} +
+
+ {{client.fi}} +
+
+
+
+
+ + +

{{$t('saleLines')}}

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{{$t('reference')}}{{$t('quantity')}}{{$t('concept')}}{{$t('price')}}{{$t('discount')}}{{$t('vat')}}{{$t('amount')}}
{{sale.itemFk | zerofill('000000')}}{{sale.quantity}}{{sale.concept}}{{sale.price | currency('EUR', + $i18n.locale)}}{{(sale.discount / 100) | + percentage}}{{sale.vatType}}{{sale.price * sale.quantity * (1 - + sale.discount / 100) | currency('EUR', $i18n.locale)}}
+ + {{sale.tag5}} {{sale.value5}} + + + {{sale.tag6}} {{sale.value6}} + + + {{sale.tag7}} {{sale.value7}} + +
+ {{$t('subtotal')}} + {{getSubTotal() | currency('EUR', $i18n.locale)}}
+ + +
+ +
+

{{$t('services.title')}}

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{{$t('services.theader.quantity')}}{{$t('services.theader.concept')}}{{$t('services.theader.price')}}{{$t('services.theader.vat')}}{{$t('services.theader.amount')}}
{{service.quantity}}{{service.description}}{{service.price | currency('EUR', $i18n.locale)}} + {{service.taxDescription}}{{service.price | currency('EUR', $i18n.locale)}} +
+ {{$t('services.tfoot.subtotal')}} + {{serviceTotal | currency('EUR', $i18n.locale)}}
+ * {{ $t('services.warning') }} +
+ +
+
+ +
+

{{$t('packagings.title')}}

+ + + + + + + + + + + + + + + +
{{$t('packagings.theader.reference')}}{{$t('packagings.theader.quantity')}}{{$t('packagings.theader.concept')}}
{{packaging.itemFk | zerofill('000000')}}{{packaging.quantity}}{{packaging.name}}
+
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{{$t('taxes.title')}}
{{$t('taxes.theader.type')}}{{$t('taxes.theader.taxBase')}}{{$t('taxes.theader.tax')}}{{$t('taxes.theader.fee')}}
{{tax.name}} + {{tax.Base | currency('EUR', $i18n.locale)}} + {{tax.vatPercent | percentage}}{{tax.tax | currency('EUR', $i18n.locale)}}
{{$t('subtotal')}} + {{getTotalBase() | currency('EUR', $i18n.locale)}} + {{getTotalTax()| currency('EUR', $i18n.locale)}}
{{$t('total')}}{{getTotal() | currency('EUR', + $i18n.locale)}}
+
+ + + +
+
+
+
+
+
+ +
+
+ {{$t('plantPassport')}}
+
+
+
+
+
+ A + {{getBotanical()}} +
+
+ B + ES17462130 +
+
+ C + {{ticket.id}} +
+
+ D + ES +
+
+
+
+
+ +
+
+ +
+
+
{{$t('digitalSignature')}}
+
+ +
{{signature.created | date('%d-%m-%Y')}}
+
+
+
+ +
+
+ +
+

{{$t('observations')}}

+

{{ticket.description}}

- - - -
- +
+ + + +
+ + \ No newline at end of file diff --git a/print/templates/reports/delivery-note/delivery-note.js b/print/templates/reports/delivery-note/delivery-note.js index 7045ef709..9c06f807b 100755 --- a/print/templates/reports/delivery-note/delivery-note.js +++ b/print/templates/reports/delivery-note/delivery-note.js @@ -54,7 +54,11 @@ module.exports = { footerType() { const translatedType = this.$t(this.deliverNoteType); return `${translatedType} ${this.id}`; + }, + hasObservations() { + return this.ticket.description !== null; } + }, methods: { fetchClient(id) { diff --git a/print/templates/reports/delivery-note/locale/en.yml b/print/templates/reports/delivery-note/locale/en.yml index c74b87520..5902da8b3 100644 --- a/print/templates/reports/delivery-note/locale/en.yml +++ b/print/templates/reports/delivery-note/locale/en.yml @@ -46,4 +46,5 @@ taxes: fee: Fee tfoot: subtotal: Subtotal - total: Total \ No newline at end of file + total: Total +observations: Observations \ No newline at end of file diff --git a/print/templates/reports/delivery-note/locale/es.yml b/print/templates/reports/delivery-note/locale/es.yml index 5c5a6af4d..d87198f45 100644 --- a/print/templates/reports/delivery-note/locale/es.yml +++ b/print/templates/reports/delivery-note/locale/es.yml @@ -47,4 +47,5 @@ taxes: fee: Cuota tfoot: subtotal: Subtotal - total: Total \ No newline at end of file + total: Total +observations: Observaciones \ No newline at end of file diff --git a/print/templates/reports/delivery-note/locale/fr.yml b/print/templates/reports/delivery-note/locale/fr.yml index df7ca053b..603623a47 100644 --- a/print/templates/reports/delivery-note/locale/fr.yml +++ b/print/templates/reports/delivery-note/locale/fr.yml @@ -47,4 +47,5 @@ taxes: fee: Quote tfoot: subtotal: Total partiel - total: Total \ No newline at end of file + total: Total +observations: Observations \ No newline at end of file diff --git a/print/templates/reports/delivery-note/locale/pt.yml b/print/templates/reports/delivery-note/locale/pt.yml index 1f418b31f..fb49d230b 100644 --- a/print/templates/reports/delivery-note/locale/pt.yml +++ b/print/templates/reports/delivery-note/locale/pt.yml @@ -47,4 +47,5 @@ taxes: fee: Compartilhado tfoot: subtotal: Subtotal - total: Total \ No newline at end of file + total: Total +observations: Observações \ No newline at end of file diff --git a/print/templates/reports/delivery-note/sql/ticket.sql b/print/templates/reports/delivery-note/sql/ticket.sql index f78c72544..9eac2d322 100644 --- a/print/templates/reports/delivery-note/sql/ticket.sql +++ b/print/templates/reports/delivery-note/sql/ticket.sql @@ -2,7 +2,11 @@ SELECT t.id, t.shipped, c.code companyCode, - t.packages + t.packages, + tto.description FROM ticket t JOIN company c ON c.id = t.companyFk + LEFT JOIN ticketObservation tto + ON tto.ticketFk = t.id + AND tto.observationTypeFk = (SELECT id FROM observationType WHERE code = 'deliveryNote') WHERE t.id = ? \ No newline at end of file diff --git a/print/templates/reports/invoice/invoice.html b/print/templates/reports/invoice/invoice.html index 1d646a0db..aed4b38f3 100644 --- a/print/templates/reports/invoice/invoice.html +++ b/print/templates/reports/invoice/invoice.html @@ -264,7 +264,7 @@
{{row.code}}{{row.description}}{{row.description || $t('services') }} {{row.stems | number($i18n.locale)}} {{row.netKg | number($i18n.locale)}} {{row.subtotal | currency('EUR', $i18n.locale)}}
+ + + + + +
+ + + + + +
+
+
+
+
+

{{$t('title')}}

+ + + + + + + + + + + + + + + +
{{$t('supplierId')}}{{invoice.supplierId}}
{{$t('invoiceId')}}{{invoice.id}}
{{$t('date')}}{{invoice.created | date('%d-%m-%Y')}}
+
+
+
+
+
{{$t('invoiceData')}}
+
+

{{invoice.name}}

+
+ {{invoice.postalAddress}} +
+
+ {{invoice.postcodeCity}} +
+
+ {{$t('fiscalId')}}: {{invoice.nif}} +
+
+ {{$t('phone')}}: {{invoice.phone}} +
+
+
+
+
+ +
+
+
+

{{$t('invoiceId')}} +

+
+
+ {{entry.id}} +
+
+
+

{{$t('date')}}

+
+
+
+ {{entry.landed | date}} +
+
+ +
+

{{$t('reference')}}

+
+
+
+ {{entry.ref}} +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
{{$t('item')}}{{$t('quantity')}}{{$t('buyingValue')}}{{$t('amount')}}
{{buy.name}}{{buy.quantity}}{{buy.buyingValue}}{{buyImport(buy) | currency('EUR', $i18n.locale)}}
+ + {{buy.tag5}} {{buy.value5}} + + + {{buy.tag6}} {{buy.value6}} + + + {{buy.tag7}} {{buy.value7}} + +
+ {{$t('subtotal')}} + {{entrySubtotal(entry) | currency('EUR', $i18n.locale)}}
+
+ + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{{$t('taxBreakdown')}}
{{$t('type')}} + {{$t('taxBase')}} + {{$t('tax')}}{{$t('fee')}}
{{tax.name}} + {{tax.taxableBase | currency('EUR', $i18n.locale)}} + {{tax.rate | percentage}}{{tax.vat | currency('EUR', $i18n.locale)}}
{{$t('subtotal')}} + {{sumTotal(taxes, 'taxableBase') | currency('EUR', $i18n.locale)}} + {{sumTotal(taxes, 'vat') | currency('EUR', $i18n.locale)}}
{{$t('total')}}{{taxTotal() | currency('EUR', $i18n.locale)}}
+ +
+
{{$t('notes')}}
+
+ {{invoice.footNotes}} +
+
+
+ + + +
+
+
+
{{$t('observations')}}
+
+
{{$t('payMethod')}}
+
{{invoice.payMethod}}
+
+
+
+
+ + +
+
+
+ + + +
+ + diff --git a/print/templates/reports/invoiceIn/invoiceIn.js b/print/templates/reports/invoiceIn/invoiceIn.js new file mode 100755 index 000000000..526c40fc6 --- /dev/null +++ b/print/templates/reports/invoiceIn/invoiceIn.js @@ -0,0 +1,94 @@ +const Component = require(`vn-print/core/component`); +const reportHeader = new Component('report-header'); +const reportFooter = new Component('report-footer'); + +module.exports = { + name: 'invoiceIn', + async serverPrefetch() { + this.invoice = await this.fetchInvoice(this.id); + this.taxes = await this.fetchTaxes(this.id); + + if (!this.invoice) + throw new Error('Something went wrong'); + + const entries = await this.fetchEntry(this.id); + const buys = await this.fetchBuy(this.id); + + const map = new Map(); + + for (let entry of entries) { + entry.buys = []; + + map.set(entry.id, entry); + } + + for (let buy of buys) { + const entry = map.get(buy.entryFk); + + if (entry) entry.buys.push(buy); + } + + this.entries = entries; + }, + computed: { + }, + methods: { + fetchInvoice(id) { + return this.findOneFromDef('invoice', [id]); + }, + fetchEntry(id) { + return this.rawSqlFromDef('entry', [id]); + }, + fetchBuy(id) { + return this.rawSqlFromDef('buy', [id]); + }, + async fetchTaxes(id) { + const taxes = await this.rawSqlFromDef(`taxes`, [id]); + return this.taxVat(taxes); + }, + buyImport(buy) { + return buy.quantity * buy.buyingValue; + }, + entrySubtotal(entry) { + let subTotal = 0.00; + for (let buy of entry.buys) + subTotal += this.buyImport(buy); + + return subTotal; + }, + sumTotal(rows, prop) { + let total = 0.00; + for (let row of rows) + total += parseFloat(row[prop]); + + return total; + }, + taxVat(taxes) { + for (tax of taxes) { + let vat = 0; + if (tax.rate && tax.taxableBase) + vat = (tax.rate / 100) * tax.taxableBase; + + tax.vat = vat; + } + + return taxes; + }, + taxTotal() { + const base = this.sumTotal(this.taxes, 'taxableBase'); + const vat = this.sumTotal(this.taxes, 'vat'); + + return base + vat; + } + }, + components: { + 'report-header': reportHeader.build(), + 'report-footer': reportFooter.build(), + }, + props: { + id: { + type: Number, + description: 'The invoice id' + } + } +}; diff --git a/print/templates/reports/invoiceIn/locale/en.yml b/print/templates/reports/invoiceIn/locale/en.yml new file mode 100644 index 000000000..92d3b0c2d --- /dev/null +++ b/print/templates/reports/invoiceIn/locale/en.yml @@ -0,0 +1,25 @@ +reportName: invoice +title: Agricultural invoice +invoiceId: Agricultural invoice +supplierId: Proveedor +invoiceData: Invoice data +reference: Reference +fiscalId: FI / NIF +phone: Phone +date: Date +item: Item +quantity: Qty. +concept: Concept +buyingValue: PSP/u +discount: Disc. +vat: VAT +amount: Amount +type: Type +taxBase: Tax base +tax: Tax +fee: Fee +total: Total +subtotal: Subtotal +taxBreakdown: Tax breakdown +observations: Observations +payMethod: Pay method diff --git a/print/templates/reports/invoiceIn/locale/es.yml b/print/templates/reports/invoiceIn/locale/es.yml new file mode 100644 index 000000000..f2fb28e64 --- /dev/null +++ b/print/templates/reports/invoiceIn/locale/es.yml @@ -0,0 +1,25 @@ +reportName: factura +title: Factura Agrícola +invoiceId: Factura Agrícola +supplierId: Proveedor +invoiceData: Datos de facturación +reference: Referencia +fiscalId: CIF / NIF +phone: Tlf +date: Fecha +item: Artículo +quantity: Cant. +concept: Concepto +buyingValue: PVP/u +discount: Dto. +vat: IVA +amount: Importe +type: Tipo +taxBase: Base imp. +tax: Tasa +fee: Cuota +total: Total +subtotal: Subtotal +taxBreakdown: Desglose impositivo +observations: Observaciones +payMethod: Método de pago diff --git a/print/templates/reports/invoiceIn/sql/buy.sql b/print/templates/reports/invoiceIn/sql/buy.sql new file mode 100644 index 000000000..28a80ff9c --- /dev/null +++ b/print/templates/reports/invoiceIn/sql/buy.sql @@ -0,0 +1,18 @@ +SELECT + b.id, + e.id entryFk, + it.name, + b.quantity, + b.buyingValue, + (b.quantity * b.buyingValue) total, + it.tag5, + it.value5, + it.tag6, + it.value6, + it.tag7, + it.value7 + FROM entry e + JOIN invoiceIn i ON i.id = e.invoiceInFk + JOIN buy b ON b.entryFk = e.id + JOIN item it ON it.id = b.itemFk + WHERE i.id = ? diff --git a/print/templates/reports/invoiceIn/sql/entry.sql b/print/templates/reports/invoiceIn/sql/entry.sql new file mode 100644 index 000000000..0b29cd81c --- /dev/null +++ b/print/templates/reports/invoiceIn/sql/entry.sql @@ -0,0 +1,8 @@ +SELECT + e.id, + t.landed, + e.ref + FROM entry e + JOIN invoiceIn i ON i.id = e.invoiceInFk + JOIN travel t ON t.id = e.travelFk + WHERE i.id = ? diff --git a/print/templates/reports/invoiceIn/sql/invoice.sql b/print/templates/reports/invoiceIn/sql/invoice.sql new file mode 100644 index 000000000..fe9ef1e9e --- /dev/null +++ b/print/templates/reports/invoiceIn/sql/invoice.sql @@ -0,0 +1,14 @@ +SELECT + i.id, + s.id supplierId, + i.created, + s.name, + s.street AS postalAddress, + s.nif, + s.phone, + p.name payMethod + FROM invoiceIn i + JOIN supplier s ON s.id = i.supplierFk + JOIN company c ON c.id = i.companyFk + JOIN payMethod p ON p.id = s.payMethodFk + WHERE i.id = ? diff --git a/print/templates/reports/invoiceIn/sql/taxes.sql b/print/templates/reports/invoiceIn/sql/taxes.sql new file mode 100644 index 000000000..20df33f83 --- /dev/null +++ b/print/templates/reports/invoiceIn/sql/taxes.sql @@ -0,0 +1,8 @@ +SELECT + ti.iva as name, + ti.PorcentajeIva as rate, + iit.taxableBase + FROM invoiceIn ii + JOIN invoiceInTax iit ON ii.id = iit.invoiceInFk + JOIN sage.TiposIva ti ON ti.CodigoIva = iit.taxTypeSageFk + WHERE ii.id = ?;