From 6b64b2b41961d241f0ba023086483a4ab98c5a89 Mon Sep 17 00:00:00 2001 From: Bernat Date: Thu, 20 Sep 2018 12:57:17 +0200 Subject: [PATCH 1/8] update structure db --- .../changes/1.0.1-OnlyLocal/01-localLog.sql | 4 + .../02-updateTriggerTickets.sql | 21 +++ .../05-updateTriggerClient.sql | 0 .../install/changes/1.1.0/04-orderAddItem.sql | 23 ++- .../changes/1.1.0/05-basketAddItem.sql | 6 +- .../db/install/changes/1.1.0/06-addItem.sql | 98 ----------- .../install/changes/1.1.0/07-orderAddItem.sql | 27 --- .../1.1.0/09-ticketComponentUpdateSale.sql | 154 ++++++++++++++++++ 8 files changed, 196 insertions(+), 137 deletions(-) create mode 100644 services/db/install/changes/1.0.1-OnlyLocal/01-localLog.sql create mode 100644 services/db/install/changes/1.0.1-OnlyLocal/02-updateTriggerTickets.sql rename services/db/install/changes/{1.0.1 => 1.0.1-OnlyLocal}/05-updateTriggerClient.sql (100%) delete mode 100644 services/db/install/changes/1.1.0/06-addItem.sql delete mode 100644 services/db/install/changes/1.1.0/07-orderAddItem.sql create mode 100644 services/db/install/changes/1.1.0/09-ticketComponentUpdateSale.sql diff --git a/services/db/install/changes/1.0.1-OnlyLocal/01-localLog.sql b/services/db/install/changes/1.0.1-OnlyLocal/01-localLog.sql new file mode 100644 index 000000000..4d1c48a74 --- /dev/null +++ b/services/db/install/changes/1.0.1-OnlyLocal/01-localLog.sql @@ -0,0 +1,4 @@ +CREATE TABLE `vn`.`localLog` ( + `id` INT NOT NULL AUTO_INCREMENT, + `ticketFk` VARCHAR(45) NULL, + PRIMARY KEY (`id`)); diff --git a/services/db/install/changes/1.0.1-OnlyLocal/02-updateTriggerTickets.sql b/services/db/install/changes/1.0.1-OnlyLocal/02-updateTriggerTickets.sql new file mode 100644 index 000000000..9594391cf --- /dev/null +++ b/services/db/install/changes/1.0.1-OnlyLocal/02-updateTriggerTickets.sql @@ -0,0 +1,21 @@ +DROP TRIGGER IF EXISTS `vn2008`.`TicketsAfterUpdate`; + +DELIMITER $$ +USE `vn2008`$$ +CREATE DEFINER=`root`@`%` TRIGGER `vn2008`.`TicketsAfterUpdate` + AFTER UPDATE ON `Tickets` FOR EACH ROW +BEGIN + IF NEW.Id_Ruta IS NULL AND OLD.Id_Ruta IS NOT NULL THEN + INSERT INTO vn.routeLog(originFk, userFk, `action`, description) + VALUES (OLD.Id_Ruta, account.userGetId(), 'update', CONCAT('Saca el ticket ', OLD.Id_Ticket, ' de la ruta')); + ELSEIF NOT (NEW.Id_Ruta <=> OLD.Id_Ruta) THEN + INSERT INTO vn.routeLog(originFk, userFk, `action`, description) + VALUES (NEW.Id_Ruta, account.userGetId(), 'update', CONCAT('Añade el ticket ', OLD.Id_Ticket, ' a la ruta')); + END IF; + + CALL stock.queueAdd ('ticket', NEW.Id_Ticket, OLD.Id_Ticket); + + INSERT INTO vn.localLog(ticketFk) + VALUES(NEW.Id_Ticket); +END$$ +DELIMITER ; diff --git a/services/db/install/changes/1.0.1/05-updateTriggerClient.sql b/services/db/install/changes/1.0.1-OnlyLocal/05-updateTriggerClient.sql similarity index 100% rename from services/db/install/changes/1.0.1/05-updateTriggerClient.sql rename to services/db/install/changes/1.0.1-OnlyLocal/05-updateTriggerClient.sql diff --git a/services/db/install/changes/1.1.0/04-orderAddItem.sql b/services/db/install/changes/1.1.0/04-orderAddItem.sql index c76d521e1..be3159c61 100644 --- a/services/db/install/changes/1.1.0/04-orderAddItem.sql +++ b/services/db/install/changes/1.1.0/04-orderAddItem.sql @@ -4,10 +4,10 @@ DROP procedure IF EXISTS `orderAddItem`; DELIMITER $$ USE `hedera`$$ CREATE DEFINER=`root`@`%` PROCEDURE `orderAddItem`( - vWarehouse INT, + vOrder INT, + vWarehouse INT, vItem INT, - vAmount INT, - vOrder INT) + vAmount INT) BEGIN DECLARE vRow INT; DECLARE vAdd INT; @@ -17,27 +17,34 @@ BEGIN DECLARE vRate INT; DECLARE vShipment DATE; DECLARE vPrice DECIMAL(10,2); - + DECLARE vDate DATE; + DECLARE vAddress INT; + DECLARE vAgencyMode INT; DECLARE cur CURSOR FOR SELECT grouping, price, rate FROM tmp.bionic_price WHERE warehouse_id = vWarehouse AND item_id = vItem ORDER BY grouping DESC; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; RESIGNAL; END; - CALL bionic_from_item (vItem); + SELECT date_send, address_id, agency_id + INTO vDate, vAddress, vAgencyMode + FROM `order` + WHERE id = vOrder; + + CALL vn2008.bionic_from_item(vDate, vAddress, vAgencyMode, vItem); START TRANSACTION; - + SELECT shipped INTO vShipment FROM tmp.travel_tree WHERE warehouseFk = vWarehouse; diff --git a/services/db/install/changes/1.1.0/05-basketAddItem.sql b/services/db/install/changes/1.1.0/05-basketAddItem.sql index d9ea6f717..fdd575807 100644 --- a/services/db/install/changes/1.1.0/05-basketAddItem.sql +++ b/services/db/install/changes/1.1.0/05-basketAddItem.sql @@ -11,10 +11,8 @@ BEGIN DECLARE vOrder INT; SET vOrder = myBasketGetId(); - - CALL bionic_from_item (vItem); - - CALL addItem(vWarehouse, vItem, vAmount, vOrder); + + CALL orderAddItem(vOrder,vWarehouse, vItem, vAmount); END$$ DELIMITER ; diff --git a/services/db/install/changes/1.1.0/06-addItem.sql b/services/db/install/changes/1.1.0/06-addItem.sql deleted file mode 100644 index 8a15132af..000000000 --- a/services/db/install/changes/1.1.0/06-addItem.sql +++ /dev/null @@ -1,98 +0,0 @@ -USE `hedera`; -DROP procedure IF EXISTS `addItem`; - -DELIMITER $$ -USE `hedera`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `addItem`( - vWarehouse INT, - vItem INT, - vAmount INT, - vOrder INT) -BEGIN - DECLARE vRow INT; - DECLARE vAdd INT; - DECLARE vAvailable INT; - DECLARE vDone BOOL; - DECLARE vGrouping INT; - DECLARE vRate INT; - DECLARE vShipment DATE; - DECLARE vPrice DECIMAL(10,2); - DECLARE cur CURSOR FOR - SELECT grouping, price, rate - FROM tmp.bionic_price - WHERE warehouse_id = vWarehouse - AND item_id = vItem - ORDER BY grouping DESC; - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - START TRANSACTION; - - SELECT shipped INTO vShipment - FROM tmp.travel_tree - WHERE warehouseFk = vWarehouse; - - SELECT available INTO vAvailable - FROM tmp.bionic_lot - WHERE warehouse_id = vWarehouse - AND item_id = vItem; - - IF vAmount > vAvailable - THEN - CALL util.throw ('ORDER_ROW_UNAVAILABLE'); - END IF; - - OPEN cur; - - l: LOOP - SET vDone = FALSE; - - FETCH cur INTO vGrouping, vPrice, vRate; - - IF vDone THEN - LEAVE l; - END IF; - - SET vAdd = vAmount - MOD(vAmount, vGrouping); - SET vAmount = vAmount - vAdd; - - IF vAdd = 0 THEN - ITERATE l; - END IF; - - INSERT INTO order_row SET - order_id = vOrder, - item_id = vItem, - warehouse_id = vWarehouse, - shipment = vShipment, - rate = vRate, - amount = vAdd, - price = vPrice; - - SET vRow = LAST_INSERT_ID(); - - INSERT INTO order_component (order_row_id, component_id, price) - SELECT vRow, c.component_id, c.cost - FROM tmp.bionic_component c - JOIN bi.tarifa_componentes t - ON t.Id_Componente = c.component_id - AND (t.tarifa_class IS NULL OR t.tarifa_class = vRate) - WHERE c.warehouse_id = vWarehouse - AND c.item_id = vItem; - END LOOP; - - CLOSE cur; - COMMIT; - - CALL vn2008.bionic_free (); -END$$ - -DELIMITER ; - diff --git a/services/db/install/changes/1.1.0/07-orderAddItem.sql b/services/db/install/changes/1.1.0/07-orderAddItem.sql deleted file mode 100644 index ef5a867d9..000000000 --- a/services/db/install/changes/1.1.0/07-orderAddItem.sql +++ /dev/null @@ -1,27 +0,0 @@ -USE `hedera`; -DROP procedure IF EXISTS `orderAddItem`; - -DELIMITER $$ -USE `hedera`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `orderAddItem`( - vWarehouse INT, - vItem INT, - vAmount INT, - vOrder INT) -BEGIN - DECLARE vDate DATE; - DECLARE vAddress INT; - DECLARE vAgencyMode INT; - - SELECT date_send, address_id, agency_id - INTO vDate, vAddress, vAgencyMode - FROM `order` - WHERE id = vOrder; - - CALL vn2008.bionic_from_item(vDate, vAddress, vAgencyMode, vItem); - - CALL addItem(vWarehouse, vItem, vAmount, vOrder); -END$$ - -DELIMITER ; - diff --git a/services/db/install/changes/1.1.0/09-ticketComponentUpdateSale.sql b/services/db/install/changes/1.1.0/09-ticketComponentUpdateSale.sql new file mode 100644 index 000000000..80da69009 --- /dev/null +++ b/services/db/install/changes/1.1.0/09-ticketComponentUpdateSale.sql @@ -0,0 +1,154 @@ +USE `vn`; +DROP procedure IF EXISTS `ticketComponentUpdateSale`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentUpdateSale`(vOption INT) +BEGIN +/** + * A partir de la tabla tmp.sale, crea los Movimientos_componentes + * y modifica el campo Preu de la tabla Movimientos + * + * @param i_option integer tipo de actualizacion + * @param table tmp.sale tabla memory con el campo Id_Movimiento, warehouse_id + **/ + DECLARE vComponentFk INT; + DECLARE vRenewComponents BOOLEAN; + DECLARE vKeepPrices BOOLEAN; + + CASE vOption + WHEN 1 THEN + SET vRenewComponents = TRUE; + SET vKeepPrices = FALSE; + WHEN 2 THEN + SET vComponentFk = 17; + SET vRenewComponents = TRUE; + SET vKeepPrices = TRUE; + WHEN 3 THEN + SET vComponentFk = 37; + SET vRenewComponents = TRUE; + SET vKeepPrices = TRUE; + WHEN 4 THEN + SET vComponentFk = 34; + SET vRenewComponents = TRUE; + SET vKeepPrices = TRUE; + WHEN 5 THEN + SET vComponentFk = 35; + SET vRenewComponents = TRUE; + SET vKeepPrices = TRUE; + WHEN 6 THEN + SET vComponentFk = 36; + SET vRenewComponents = TRUE; + SET vKeepPrices = TRUE; + WHEN 7 THEN + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.8, 3) + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + AND sc.componentFk NOT IN (28, 29) + GROUP BY s.id; + + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, 29, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.2, 3) + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + AND sc.componentFk NOT IN (28, 29) + GROUP BY s.id; + + SET vRenewComponents = FALSE; + SET vKeepPrices = FALSE; + WHEN 8 THEN + DELETE sc.* + FROM tmp.sale tmps JOIN saleComponent sc ON sc.saleFk = tmps.saleFk; + + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100)), 3) + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id; + + SET vRenewComponents = FALSE; + SET vKeepPrices = FALSE; + WHEN 9 THEN + SET vRenewComponents = TRUE; + SET vKeepPrices = TRUE; + END CASE; + + IF vRenewComponents THEN + DELETE sc.* + FROM tmp.sale tmps + JOIN saleComponent sc ON sc.saleFk = tmps.saleFk + JOIN componentRate cr ON cr.id = sc.componentFk + WHERE cr.isRenewable; + + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, tc.componentFk, ROUND(tc.cost,3) + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + AND sc.componentFk = tc.componentFk + LEFT JOIN componentRate cr ON cr.id = tc.componentFk + WHERE IF(sc.componentFk IS NULL AND NOT cr.isRenewable, FALSE, TRUE); + END IF; + + IF vKeepPrices THEN + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, vComponentFk, ROUND((s.price * (100 - s.discount) / 100) - SUM(sc.value), 3) dif + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + WHERE sc.saleFk <> vComponentFk + GROUP BY s.id + HAVING dif <> 0; + ELSE + UPDATE sale s + JOIN item i on i.id = s.itemFk + JOIN itemType it on it.id = i.typeFk + JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk + FROM saleComponent sc + JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk + GROUP BY sc.saleFk) sc ON sc.saleFk = s.id + SET s.price = sumValue + WHERE it.code != 'PRT'; + + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, 21, ROUND((s.price * (100 - s.discount) / 100) - sum(value),3) saleValue + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + WHERE sc.componentFk != 21 + GROUP BY s.id + HAVING ROUND(saleValue, 4) <> 0; + END IF; + + UPDATE sale s + JOIN ( + SELECT SUM(sc.value) sumValue, sc.saleFk + FROM saleComponent sc + JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk + JOIN componentRate cr ON cr.id = sc.componentFk + JOIN componentTypeRate ctr on ctr.id = cr.componentTypeRate AND ctr.base + GROUP BY sc.saleFk) sc ON sc.saleFk = s.id + SET s.priceFixed = sumValue, s.isPriceFixed = 1; + + DELETE sc.* + FROM saleComponent sc + JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk + JOIN sale s on s.id = sc.saleFk + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + WHERE it.code = 'PRT'; + + INSERT INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, 15, ROUND(s.price,3) + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN item i ON i.id = s.itemFK + JOIN itemType it ON it.id = i.typeFk + WHERE it.code = 'PRT' AND s.price > 0; +END$$ + +DELIMITER ; + From 2cd2c6bdaeb6a76df5bf1f9ce8615029610863c1 Mon Sep 17 00:00:00 2001 From: Bernat Date: Fri, 21 Sep 2018 07:28:26 +0200 Subject: [PATCH 2/8] update model agency --- .../db/install/changes/1.1.0/06-agency.sql | 2 ++ .../db/install/changes/1.1.0/07.viewAgency.sql | 18 ++++++++++++++++++ services/loopback/common/models/agency.json | 4 ++++ 3 files changed, 24 insertions(+) create mode 100644 services/db/install/changes/1.1.0/06-agency.sql create mode 100644 services/db/install/changes/1.1.0/07.viewAgency.sql diff --git a/services/db/install/changes/1.1.0/06-agency.sql b/services/db/install/changes/1.1.0/06-agency.sql new file mode 100644 index 000000000..3dcfaf05d --- /dev/null +++ b/services/db/install/changes/1.1.0/06-agency.sql @@ -0,0 +1,2 @@ + ALTER TABLE `vn2008`.`agency` +ADD COLUMN `code` VARCHAR(45) NULL DEFAULT NULL AFTER `zone_label`; \ No newline at end of file diff --git a/services/db/install/changes/1.1.0/07.viewAgency.sql b/services/db/install/changes/1.1.0/07.viewAgency.sql new file mode 100644 index 000000000..2759983a6 --- /dev/null +++ b/services/db/install/changes/1.1.0/07.viewAgency.sql @@ -0,0 +1,18 @@ +USE `vn`; +CREATE + OR REPLACE ALGORITHM = UNDEFINED + DEFINER = `root`@`%` + SQL SECURITY DEFINER +VIEW `agency` AS + SELECT + `a`.`agency_id` AS `id`, + `a`.`name` AS `name`, + `a`.`warehouse_id` AS `warehouseFk`, + `a`.`por_volumen` AS `isVolumetric`, + `a`.`Id_Banco` AS `bankFk`, + `a`.`warehouse_alias_id` AS `warehouseAliasFk`, + `a`.`propios` AS `own`, + `a`.`zone_label` AS `labelZone`, + `a`.`code` AS `code` + FROM + `vn2008`.`agency` `a`; diff --git a/services/loopback/common/models/agency.json b/services/loopback/common/models/agency.json index 9269b3db6..fa104399c 100644 --- a/services/loopback/common/models/agency.json +++ b/services/loopback/common/models/agency.json @@ -15,6 +15,10 @@ "name": { "type": "String", "required": false + }, + "code": { + "type": "String", + "required": false } } } From fec2134b8f8a7e6b3b93ceb1cb52655162032b3f Mon Sep 17 00:00:00 2001 From: Joan Date: Fri, 21 Sep 2018 12:35:54 +0200 Subject: [PATCH 3/8] added zone descriptor #669 --- client/route/routes.json | 2 +- client/route/src/index.js | 2 + client/route/src/zone/card/index.html | 2 +- client/route/src/zone/card/index.js | 60 ++++++------------ client/route/src/zone/card/index.spec.js | 62 ++++++------------- client/route/src/zone/descriptor/index.html | 21 ++++++- client/route/src/zone/descriptor/index.js | 14 +---- .../route/src/zone/descriptor/locale/es.yml | 8 --- client/route/src/zone/descriptor/style.scss | 5 -- 9 files changed, 61 insertions(+), 115 deletions(-) delete mode 100644 client/route/src/zone/descriptor/locale/es.yml delete mode 100644 client/route/src/zone/descriptor/style.scss diff --git a/client/route/routes.json b/client/route/routes.json index 22ebe01b5..49ccab1b5 100644 --- a/client/route/routes.json +++ b/client/route/routes.json @@ -50,7 +50,7 @@ "component": "vn-zone-basic-data", "description": "Basic data", "params": { - "client": "$ctrl.client" + "zone": "$ctrl.zone" }, "menu": { "icon": "settings" diff --git a/client/route/src/index.js b/client/route/src/index.js index 428cafb81..398a6c84d 100644 --- a/client/route/src/index.js +++ b/client/route/src/index.js @@ -6,3 +6,5 @@ import './zone/descriptor'; import './zone/search-panel'; import './zone/index'; import './zone/create'; +import './zone/basic-data'; + diff --git a/client/route/src/zone/card/index.html b/client/route/src/zone/card/index.html index 093e6d42a..b2d4c0522 100644 --- a/client/route/src/zone/card/index.html +++ b/client/route/src/zone/card/index.html @@ -1,7 +1,7 @@ - + diff --git a/client/route/src/zone/card/index.js b/client/route/src/zone/card/index.js index 5a62d0eef..55bf941a0 100644 --- a/client/route/src/zone/card/index.js +++ b/client/route/src/zone/card/index.js @@ -1,58 +1,36 @@ import ngModule from '../../module'; class Controller { - constructor($http, $state) { + constructor($http, $stateParams) { this.$http = $http; - this.$state = $state; - this.order = {}; - this.filter = { + this.$stateParams = $stateParams; + } + + $onInit() { + this.getCard(); + } + + getCard() { + let filter = { include: [ - {relation: 'agencyMode', scope: {fields: ['name']}}, - {relation: 'address', scope: {fields: ['nickname']}}, - {relation: 'rows', scope: {fields: ['id']}}, - { - relation: 'client', - scope: { - fields: ['salesPersonFk', 'name', 'isActive', 'isFreezed', 'isTaxDataChecked'], - include: { - relation: 'salesPerson', - fields: ['firstName', 'name'] - } - } - } + {relation: 'warehouse', fields: ['name']}, + {relation: 'agencyMode', fields: ['name']} ] }; - } - -/* getOrder() { - let json = encodeURIComponent(JSON.stringify(this.filter)); - let query = `/order/api/Orders/${this.$state.params.id}?filter=${json}`; + let json = encodeURIComponent(JSON.stringify(filter)); + let query = `/route/api/Zones/${this.$stateParams.id}?filter=${json}`; this.$http.get(query).then(res => { - if (res.data) { - this.order = res.data; - this.getTotal(); - } + if (res.data) + this.zone = res.data; }); } - getTotal() { - let query = `/order/api/Orders/${this.$state.params.id}/getTotal`; - this.$http.get(query).then(res => { - if (res.data) { - this.order.total = res.data.total; - } - }); - } - $onInit() { - this.getOrder(); - } - reload() { - this.getOrder(); - } */ + this.getCard(); + } } -Controller.$inject = ['$http', '$state']; +Controller.$inject = ['$http', '$stateParams']; ngModule.component('vnZoneCard', { template: require('./index.html'), diff --git a/client/route/src/zone/card/index.spec.js b/client/route/src/zone/card/index.spec.js index 19ed1993c..6be2098fa 100644 --- a/client/route/src/zone/card/index.spec.js +++ b/client/route/src/zone/card/index.spec.js @@ -1,15 +1,15 @@ import './index.js'; -describe('Order', () => { - describe('Component vnOrderCard', () => { +describe('Route', () => { + describe('Component vnZoneCard', () => { let $componentController; let $scope; let controller; let $httpBackend; - let $state; + let $stateParams; beforeEach(() => { - angular.mock.module('order'); + angular.mock.module('route'); }); beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => { @@ -17,50 +17,24 @@ describe('Order', () => { $httpBackend = _$httpBackend_; $httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({}); $scope = $rootScope.$new(); - $scope.card = {createOrder: () => {}}; - $state = {params: {id: 1}}; - controller = $componentController('vnOrderCard', {$scope: $scope, $state: $state}); + $stateParams = {id: 1}; + controller = $componentController('vnZoneCard', {$scope: $scope, $stateParams}); })); - describe('getOrder()', () => { - it(`should make a query, save the data in order and call get order if the response has data`, () => { - spyOn(controller, 'getTotal'); - let json = encodeURIComponent(JSON.stringify(controller.filter)); - $httpBackend.expectGET(`/order/api/Orders/${controller.$state.params.id}?filter=${json}`).respond({id: 1}); - controller.getOrder(); + describe('getCard()', () => { + it(`should make a query and define zone property`, () => { + let filter = { + include: [ + {relation: 'warehouse', fields: ['name']}, + {relation: 'agencyMode', fields: ['name']} + ] + }; + let json = encodeURIComponent(JSON.stringify(filter)); + $httpBackend.expectGET(`/route/api/Zones/1?filter=${json}`).respond({id: 1}); + controller.getCard(); $httpBackend.flush(); - expect(controller.order).toEqual({id: 1}); - expect(controller.getTotal).toHaveBeenCalledWith(); - }); - - it(`should make a query and not call getTotal if the response is not defined`, () => { - spyOn(controller, 'getTotal'); - let json = encodeURIComponent(JSON.stringify(controller.filter)); - $httpBackend.expectGET(`/order/api/Orders/${controller.$state.params.id}?filter=${json}`).respond(undefined); - controller.getOrder(); - $httpBackend.flush(); - - expect(controller.order).toEqual({}); - expect(controller.getTotal).not.toHaveBeenCalledWith(); - }); - }); - - describe('getTotal()', () => { - it(`should make a query and save the data in order.total`, () => { - $httpBackend.expectGET(`/order/api/Orders/${controller.$state.params.id}/getTotal`).respond({total: '20M'}); - controller.getTotal(); - $httpBackend.flush(); - - expect(controller.order.total).toEqual('20M'); - }); - - it(`should make a query and not save the respones if is not defined`, () => { - $httpBackend.expectGET(`/order/api/Orders/${controller.$state.params.id}/getTotal`).respond(); - controller.getTotal(); - $httpBackend.flush(); - - expect(controller.order.total).toEqual(undefined); + expect(controller.zone).toEqual({id: 1}); }); }); }); diff --git a/client/route/src/zone/descriptor/index.html b/client/route/src/zone/descriptor/index.html index 5fd2cbc54..3f6d6e234 100644 --- a/client/route/src/zone/descriptor/index.html +++ b/client/route/src/zone/descriptor/index.html @@ -9,11 +9,26 @@
- - + + + + + + + + + + +
diff --git a/client/route/src/zone/descriptor/index.js b/client/route/src/zone/descriptor/index.js index 31ad04774..b897c5c98 100644 --- a/client/route/src/zone/descriptor/index.js +++ b/client/route/src/zone/descriptor/index.js @@ -1,18 +1,8 @@ import ngModule from '../../module'; -import './style.scss'; - -class Controller { - constructor($translate) { - this.translate = $translate; - } -} - -Controller.$inject = ['$translate']; ngModule.component('vnZoneDescriptor', { template: require('./index.html'), bindings: { - order: '<' - }, - controller: Controller + zone: '<' + } }); diff --git a/client/route/src/zone/descriptor/locale/es.yml b/client/route/src/zone/descriptor/locale/es.yml deleted file mode 100644 index feb0b4c55..000000000 --- a/client/route/src/zone/descriptor/locale/es.yml +++ /dev/null @@ -1,8 +0,0 @@ -Client: Cliente -Confirmed: Confirmado -Not confirmed: Sin confirmar -State: Estado -Landed: F. entrega -Items: Articulos -Agency: Agencia -Sales person: Comercial \ No newline at end of file diff --git a/client/route/src/zone/descriptor/style.scss b/client/route/src/zone/descriptor/style.scss deleted file mode 100644 index 469020e50..000000000 --- a/client/route/src/zone/descriptor/style.scss +++ /dev/null @@ -1,5 +0,0 @@ -vn-label-value[label=Total]{ - padding-top: 10px; - display: block; - font-size: 1.2em; -} \ No newline at end of file From 9c1197b68f052cd700b16f98868e3d4567d1c18a Mon Sep 17 00:00:00 2001 From: Joan Date: Fri, 21 Sep 2018 12:36:11 +0200 Subject: [PATCH 4/8] updated qlabel download link --- .../mailer/application/template/printer-setup/locale/es.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/mailer/application/template/printer-setup/locale/es.json b/services/mailer/application/template/printer-setup/locale/es.json index 7d3da6646..08c28c113 100644 --- a/services/mailer/application/template/printer-setup/locale/es.json +++ b/services/mailer/application/template/printer-setup/locale/es.json @@ -4,7 +4,7 @@ "dear": "Estimado cliente,", "bodyDescription": "Siga las intrucciones especificadas en este correo para llevar a cabo la instalación de la impresora.", "followGuide": "Puede utilizar como guía, el video del montaje del ribon y la cinta https://www.youtube.com/watch?v=qhb0kgQF3o8. También necesitará el QLabel, el programa para imprimir las cintas.", - "downloadFrom": "Puede descargarlo desde este enlace http://www.godexintl.com/en/product/type/Download/2967", + "downloadFrom": "Puede descargarlo desde este enlace http://ww.godexintl.com/es1/download/downloads/Download/2996", "sectionQLabelTitle": "Utilización de QLabel", "sectionQLabelDescription": "Para utilizar el programa de impresión de cintas siga estos pasos:", "sectionQLabelStep1": "Abra el programa QLabel.", From 6fc85b0e5a901617a8e1fb24f9e325df5a68fea3 Mon Sep 17 00:00:00 2001 From: Bernat Date: Fri, 21 Sep 2018 15:01:51 +0200 Subject: [PATCH 5/8] refactor fixtures, and fix / refactor test --- e2e/helpers/selectors.js | 2 +- e2e/paths/ticket-module/03_list_sale.spec.js | 8 +- .../06_edit_basic_data_steps.spec.js | 2 +- e2e/paths/ticket-module/07_edit_sale.spec.js | 6 +- .../auth/server/boot/specs/routes.spec.js | 17 +- services/db/install/dump/fixtures.sql | 229 +++++++++--------- services/loopback/common/locale/en.json | 6 +- .../client/specs/addressesPropagateRe.spec.js | 17 +- .../methods/client/specs/getCard.spec.js | 2 +- .../methods/client/specs/getDebt.spec.js | 2 +- .../methods/client/specs/getMana.spec.js | 2 +- .../methods/client/specs/summary.spec.js | 4 +- .../common/methods/sale/moveToTicket.js | 2 +- .../loopback/common/methods/sale/reserve.js | 4 +- .../methods/sale/specs/moveToTicket.spec.js | 38 ++- .../sale/specs/priceDifference.spec.js | 4 +- .../common/methods/sale/specs/reserve.spec.js | 30 +-- .../ticket/specs/componentUpdate.spec.js | 71 +++++- .../ticket/specs/getSalespersonMana.spec.js | 2 +- .../methods/ticket/specs/getTaxes.spec.js | 2 +- .../methods/ticket/specs/getTotal.spec.js | 2 +- .../methods/ticket/specs/getVAT.spec.js | 2 +- .../methods/ticket/specs/summary.spec.js | 4 +- .../specs/getCurrentWorkerMana.spec.js | 2 +- .../methods/order/specs/getTaxes.spec.js | 2 +- .../methods/order/specs/getTotal.spec.js | 2 +- 26 files changed, 254 insertions(+), 210 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 1e238b2c0..28070cfe1 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -367,7 +367,7 @@ export default { addressSelect: `vn-autocomplete[field="$ctrl.ticket.addressFk"] input`, addressSelectSecondOption: `vn-autocomplete[field="$ctrl.ticket.addressFk"] vn-drop-down ul > li:nth-child(2)`, agencySelect: `vn-autocomplete[field="$ctrl.ticket.agencyModeFk"] input`, - agencySelectFifthOption: `vn-autocomplete[field="$ctrl.ticket.agencyModeFk"] vn-drop-down ul > li:nth-child(5)`, + agencySelectOptionSix: `vn-autocomplete[field="$ctrl.ticket.agencyModeFk"] vn-drop-down ul > li:nth-child(6)`, nextStepButton: `vn-step-control > section > section.buttons > section:nth-child(2) > vn-button`, finalizeButton: `vn-step-control > section > section.buttons > section:nth-child(2) > vn-submit`, stepTwoTotalPriceDif: `vn-ticket-data-step-two > form > vn-card > div > vn-horizontal > table > tfoot > tr > td:nth-child(4)`, diff --git a/e2e/paths/ticket-module/03_list_sale.spec.js b/e2e/paths/ticket-module/03_list_sale.spec.js index 3391be521..878febd85 100644 --- a/e2e/paths/ticket-module/03_list_sale.spec.js +++ b/e2e/paths/ticket-module/03_list_sale.spec.js @@ -68,7 +68,7 @@ describe('Ticket List sale path', () => { .wait(selectors.ticketSales.firstSaleText) .getInnerText(selectors.ticketSales.firstSalePrice) .then(value => { - expect(value).toContain('€11.42'); + expect(value).toContain('€9.10'); }); }); @@ -86,7 +86,7 @@ describe('Ticket List sale path', () => { .wait(selectors.ticketSales.firstSaleText) .getInnerText(selectors.ticketSales.firstSaleImport) .then(value => { - expect(value).toContain('57.10'); + expect(value).toContain('45.50'); }); }); @@ -104,7 +104,7 @@ describe('Ticket List sale path', () => { .wait(selectors.ticketSales.secondSaleText) .getInnerText(selectors.ticketSales.secondSalePrice) .then(value => { - expect(value).toContain('€1.30'); + expect(value).toContain('€1.07'); }); }); @@ -122,7 +122,7 @@ describe('Ticket List sale path', () => { .wait(selectors.ticketSales.secondSaleText) .getInnerText(selectors.ticketSales.secondSaleImport) .then(value => { - expect(value).toContain('13.00'); + expect(value).toContain('10.70'); }); }); }); diff --git a/e2e/paths/ticket-module/06_edit_basic_data_steps.spec.js b/e2e/paths/ticket-module/06_edit_basic_data_steps.spec.js index 4c1140d5e..99f3577f9 100644 --- a/e2e/paths/ticket-module/06_edit_basic_data_steps.spec.js +++ b/e2e/paths/ticket-module/06_edit_basic_data_steps.spec.js @@ -106,7 +106,7 @@ describe('Ticket', () => { it(`should edit the ticket agency then click next`, () => { return nightmare .waitToClick(selectors.ticketBasicData.agencySelect) - .waitToClick(selectors.ticketBasicData.agencySelectFifthOption) + .waitToClick(selectors.ticketBasicData.agencySelectOptionSix) .waitForTextInInput(selectors.ticketBasicData.agencySelect, 'Expensive') .click(selectors.ticketBasicData.nextStepButton) .waitForURL('data/step-two') diff --git a/e2e/paths/ticket-module/07_edit_sale.spec.js b/e2e/paths/ticket-module/07_edit_sale.spec.js index 0f7ac93cf..1a75a4aa6 100644 --- a/e2e/paths/ticket-module/07_edit_sale.spec.js +++ b/e2e/paths/ticket-module/07_edit_sale.spec.js @@ -60,7 +60,7 @@ describe('Ticket Edit sale path', () => { .wait(selectors.ticketSales.firstSaleText) .getInnerText(selectors.ticketSales.firstSalePrice) .then(value => { - expect(value).toEqual('€11.42'); + expect(value).toEqual('€9.10'); }); }); @@ -78,7 +78,7 @@ describe('Ticket Edit sale path', () => { .wait(selectors.ticketSales.firstSaleText) .getInnerText(selectors.ticketSales.firstSaleImport) .then(value => { - expect(value).toEqual('€57.10'); + expect(value).toEqual('€45.50'); }); }); @@ -364,7 +364,7 @@ describe('Ticket Edit sale path', () => { .waitToClick(selectors.ticketSales.moveToTicketButton) .waitForLastSnackbar() .then(result => { - expect(result).toEqual(`The sales of that ticket can't be modified`); + expect(result).toEqual(`The sales of this ticket can't be modified`); }); }); diff --git a/services/auth/server/boot/specs/routes.spec.js b/services/auth/server/boot/specs/routes.spec.js index 20b41b489..8fa68ffc2 100644 --- a/services/auth/server/boot/specs/routes.spec.js +++ b/services/auth/server/boot/specs/routes.spec.js @@ -2,19 +2,20 @@ const app = require('../../../server/server'); const routes = require('../routes'); const restoreFixtures = require('../../../../../services/db/testing_fixtures'); -describe('Auth routes', () => { - let sqlStatements = {deletes: ` - DELETE FROM salix.user WHERE id = 102; - `, inserts: ``, updates: ``}; +xdescribe('Auth routes', () => { + let route; - beforeEach(() => { - restoreFixtures(sqlStatements); + beforeAll(async() => { + route = await app.models.Route.findOne({where: {id: 102}}); }); - afterAll(() => { - restoreFixtures(sqlStatements); + beforeEach(async() => { + }); + afterAll(async() => { + + }); let User = app.models.User; let loginFunction; let logoutFunction; diff --git a/services/db/install/dump/fixtures.sql b/services/db/install/dump/fixtures.sql index 4066276b0..c9ab1f4a8 100644 --- a/services/db/install/dump/fixtures.sql +++ b/services/db/install/dump/fixtures.sql @@ -70,14 +70,15 @@ INSERT INTO `vn`.`bank`(`id`, `bank`, `account`, `cash`, `entityFk`, `isActive`) INSERT INTO `vn`.`agency`(`id`, `name`, `warehouseFk`, `isVolumetric`, `bankFk`, `warehouseAliasFk`) VALUES - (1, 'inhouse pickup' , 1, 0, 8, 1), - (2, 'Super-Man delivery' , 1, 0, 8, 1), - (3, 'Teleportation device' , 1, 0, 8, 1), - (4, 'Entanglement' , 1, 0, 8, 1), - (5, 'Quantum break device' , 1, 0, 8, 1), - (6, 'Walking' , 1, 0, 8, 1), - (7, 'Silla247' , 1, 0, 8, 1), - (8, 'Silla247Expensive' , 1, 0, 8, 1); + (1, 'inhouse pickup' , 1, 0, 8, 1), + (2, 'Super-Man delivery' , 1, 0, 8, 1), + (3, 'Teleportation device' , 1, 0, 8, 1), + (4, 'Entanglement' , 1, 0, 8, 1), + (5, 'Quantum break device' , 1, 0, 8, 1), + (6, 'Walking' , 1, 0, 8, 1), + (7, 'Silla247' , 1, 0, 8, 1), + (8, 'Silla247Expensive' , 1, 0, 8, 1), + (9, 'Abono' , 1, 0, 8, 1); UPDATE `vn`.`agencyMode` SET `id` = 1 WHERE `name` = 'inhouse pickup'; UPDATE `vn`.`agencyMode` SET `id` = 2 WHERE `name` = 'Super-Man delivery'; @@ -87,6 +88,7 @@ UPDATE `vn`.`agencyMode` SET `id` = 5 WHERE `name` = 'Quantum break device'; UPDATE `vn`.`agencyMode` SET `id` = 6 WHERE `name` = 'Walking'; UPDATE `vn`.`agencyMode` SET `id` = 7 WHERE `name` = 'Silla247'; UPDATE `vn`.`agencyMode` SET `id` = 8 WHERE `name` = 'Silla247Expensive'; +UPDATE `vn`.`agencyMode` SET `id` = 23 WHERE `name` = 'Abono'; UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 1; UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 2; @@ -96,6 +98,7 @@ UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 5; UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 2 WHERE `id` = 6; UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 7; UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 8; +UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 4 WHERE `id` = 23; UPDATE `vn`.`agencyMode` SET `web` = 1 WHERE `id` = 1; @@ -329,29 +332,29 @@ INSERT INTO `vn`.`invoiceOut`(`id`, `ref`, `serial`, `amount`, `issued`,`clientF ( 4, 'E4444444' , 'E', 290.30 , DATE_ADD(CURDATE(), INTERVAL +1 MONTH), 103, CURDATE(), 442, CURDATE(), CURDATE(), 8, 1), ( 5, 'E5555555' , 'E', 190.30 , DATE_ADD(CURDATE(), INTERVAL +2 MONTH), 103, CURDATE(), 442, CURDATE(), CURDATE(), 8, 1); - INSERT INTO `vn`.`ticket`(`id`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `landed`, `clientFk`,`nickname`, `addressFk`, `refFk`, `isDeleted`) + INSERT INTO `vn`.`ticket`(`id`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `landed`, `clientFk`,`nickname`, `addressFk`, `refFk`, `isDeleted`, `created`) VALUES - (1 , 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -15 DAY) , DATE_ADD(CURDATE(), INTERVAL -15 DAY) , 101, 'address 21', 121, NULL, 0), - (2 , 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -10 DAY) , DATE_ADD(CURDATE(), INTERVAL -10 DAY) , 101, 'address 21', 121, NULL, 0), - (3 , 2, 2, 2, DATE_ADD(CURDATE(), INTERVAL -5 DAY) , DATE_ADD(CURDATE(), INTERVAL -5 DAY) , 102, 'address 22', 122, NULL, 0), - (4 , 2, 2, 2, DATE_ADD(CURDATE(), INTERVAL -4 DAY) , DATE_ADD(CURDATE(), INTERVAL -4 DAY) , 102, 'address 22', 122, NULL, 0), - (5 , 3, 3, 3, DATE_ADD(CURDATE(), INTERVAL -3 DAY) , DATE_ADD(CURDATE(), INTERVAL -3 DAY) , 103, 'address 23', 123, NULL, 0), - (6 , 3, 3, 4, DATE_ADD(CURDATE(), INTERVAL -2 DAY) , DATE_ADD(CURDATE(), INTERVAL -2 DAY) , 103, 'address 23', 123, NULL, 0), - (7 , 4, 4, 4, DATE_ADD(CURDATE(), INTERVAL -1 DAY) , DATE_ADD(CURDATE(), INTERVAL -1 DAY) , 104, 'address 24', 124, NULL, 0), - (8 , 4, 4, 4, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 104, 'address 24', 124, NULL, 0), - (9 , 5, 5, 4, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), DATE_ADD(CURDATE(), INTERVAL -2 MONTH), 105, 'address 25', 125, NULL, 0), - (10, 6, 5, 5, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), DATE_ADD(CURDATE(), INTERVAL -3 MONTH), 105, 'address 25', 125, NULL, 0), - (11, 7, 1, 1, CURDATE() , CURDATE() , 101, 'address 21', 121, NULL, 0), - (12, 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(CURDATE(), INTERVAL +1 MONTH), 101, 'address 21', 121, NULL, 0), - (13, 2, 2, 2, DATE_ADD(CURDATE(), INTERVAL +2 MONTH), DATE_ADD(CURDATE(), INTERVAL +2 MONTH), 101, 'address 21', 121, NULL, 0), - (14, 2, 2, 2, DATE_ADD(CURDATE(), INTERVAL +3 MONTH), DATE_ADD(CURDATE(), INTERVAL +3 MONTH), 101, 'address 21', 121, NULL, 0), - (15, 3, 3, 3, DATE_ADD(CURDATE(), INTERVAL +4 MONTH), DATE_ADD(CURDATE(), INTERVAL +4 MONTH), 101, 'address 21', 121, NULL, 0), - (16, 1, 1, 1, CURDATE() , CURDATE() , 101, 'address 21', 121, NULL, 0), - (17, 4, 4, 4, CURDATE() , CURDATE() , 106, 'address 26', 126, NULL, 0), - (18, 4, 4, 4, CURDATE() , CURDATE() , 107, 'address 27', 127, NULL, 0), - (19, 5, 5, 4, CURDATE() , CURDATE() , 108, 'address 28', 128, NULL, 0), - (20, 5, 5, 4, CURDATE() , CURDATE() , 109, 'address 19', 119, NULL, 0), - (21, 5, 5, 4, CURDATE() , CURDATE() , 110, 'address 29', 129, NULL, 1); + (1 , 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -15 DAY) , DATE_ADD(CURDATE(), INTERVAL -15 DAY) , 101, 'address 21', 121, NULL, 0, DATE_ADD(CURDATE(), INTERVAL -15 DAY) ), + (2 , 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -10 DAY) , DATE_ADD(CURDATE(), INTERVAL -10 DAY) , 101, 'address 21', 121, NULL, 0, DATE_ADD(CURDATE(), INTERVAL -10 DAY) ), + (3 , 2, 2, 2, DATE_ADD(CURDATE(), INTERVAL -5 DAY) , DATE_ADD(CURDATE(), INTERVAL -5 DAY) , 102, 'address 22', 122, NULL, 0, DATE_ADD(CURDATE(), INTERVAL -5 DAY) ), + (4 , 2, 2, 2, DATE_ADD(CURDATE(), INTERVAL -4 DAY) , DATE_ADD(CURDATE(), INTERVAL -4 DAY) , 102, 'address 22', 122, NULL, 0, DATE_ADD(CURDATE(), INTERVAL -4 DAY) ), + (5 , 3, 3, 3, DATE_ADD(CURDATE(), INTERVAL -3 DAY) , DATE_ADD(CURDATE(), INTERVAL -3 DAY) , 103, 'address 23', 123, NULL, 0, DATE_ADD(CURDATE(), INTERVAL -3 DAY) ), + (6 , 3, 3, 4, DATE_ADD(CURDATE(), INTERVAL -2 DAY) , DATE_ADD(CURDATE(), INTERVAL -2 DAY) , 103, 'address 23', 123, NULL, 0, DATE_ADD(CURDATE(), INTERVAL -2 DAY) ), + (7 , 4, 4, 4, DATE_ADD(CURDATE(), INTERVAL -1 DAY) , DATE_ADD(CURDATE(), INTERVAL -1 DAY) , 104, 'address 24', 124, NULL, 0, DATE_ADD(CURDATE(), INTERVAL -1 DAY) ), + (8 , 4, 4, 4, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 104, 'address 24', 124, NULL, 0, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), + (9 , 5, 5, 4, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), DATE_ADD(CURDATE(), INTERVAL -2 MONTH), 105, 'address 25', 125, NULL, 0, DATE_ADD(CURDATE(), INTERVAL -2 MONTH)), + (10, 6, 5, 5, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), DATE_ADD(CURDATE(), INTERVAL -3 MONTH), 105, 'address 25', 125, NULL, 0, DATE_ADD(CURDATE(), INTERVAL -3 MONTH)), + (11, 7, 1, 1, CURDATE() , CURDATE() , 101, 'address 21', 121, NULL, 0, CURDATE() ), + (12, 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(CURDATE(), INTERVAL +1 MONTH), 101, 'address 21', 121, NULL, 0, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), + (13, 2, 2, 2, DATE_ADD(CURDATE(), INTERVAL +2 MONTH), DATE_ADD(CURDATE(), INTERVAL +2 MONTH), 101, 'address 21', 121, NULL, 0, DATE_ADD(CURDATE(), INTERVAL +2 MONTH)), + (14, 2, 2, 2, DATE_ADD(CURDATE(), INTERVAL +3 MONTH), DATE_ADD(CURDATE(), INTERVAL +3 MONTH), 101, 'address 21', 121, NULL, 0, DATE_ADD(CURDATE(), INTERVAL +3 MONTH)), + (15, 3, 3, 3, DATE_ADD(CURDATE(), INTERVAL +4 MONTH), DATE_ADD(CURDATE(), INTERVAL +4 MONTH), 101, 'address 21', 121, NULL, 0, DATE_ADD(CURDATE(), INTERVAL +4 MONTH)), + (16, 1, 1, 1, CURDATE() , CURDATE() , 101, 'address 21', 121, NULL, 0, CURDATE() ), + (17, 4, 4, 4, CURDATE() , CURDATE() , 106, 'address 26', 126, NULL, 0, CURDATE() ), + (18, 4, 4, 4, CURDATE() , CURDATE() , 107, 'address 27', 127, NULL, 0, CURDATE() ), + (19, 5, 5, 4, CURDATE() , CURDATE() , 108, 'address 28', 128, NULL, 0, CURDATE() ), + (20, 5, 5, 4, CURDATE() , CURDATE() , 109, 'address 19', 119, NULL, 0, CURDATE() ), + (21, 5, 5, 4, CURDATE() , CURDATE() , 110, 'address 29', 129, NULL, 1, CURDATE() ); INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `description`) VALUES @@ -361,16 +364,16 @@ INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `des INSERT INTO `vn`.`ticketTracking`(`id`, `ticketFk`, `stateFk`, `workerFk`, `created`) VALUES - (1 , 1 , 3 , 5 , CURDATE()), - (2 , 2 , 15, 5 , CURDATE()), - (3 , 3 , 16, 5 , CURDATE()), - (4 , 4 , 13, 5 , CURDATE()), - (5 , 5 , 15, 18, CURDATE()), - (6 , 6 , 16, 18, CURDATE()), - (7 , 7 , 13, 18, CURDATE()), - (8 , 8 , 15, 19, CURDATE()), - (9 , 9 , 16, 19, CURDATE()), - (10, 10, 13, 19, CURDATE()), + (1 , 1 , 16, 5 , DATE_ADD(CURDATE(), INTERVAL -15 DAY) ), + (2 , 2 , 16, 5 , DATE_ADD(CURDATE(), INTERVAL -10 DAY) ), + (3 , 3 , 16, 5 , DATE_ADD(CURDATE(), INTERVAL -5 DAY) ), + (4 , 4 , 16, 5 , DATE_ADD(CURDATE(), INTERVAL -4 DAY) ), + (5 , 5 , 16, 18, DATE_ADD(CURDATE(), INTERVAL -3 DAY) ), + (6 , 6 , 16, 18, DATE_ADD(CURDATE(), INTERVAL -2 DAY) ), + (7 , 7 , 16, 18, DATE_ADD(CURDATE(), INTERVAL -1 DAY) ), + (8 , 8 , 16, 19, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), + (9 , 9 , 16, 19, DATE_ADD(CURDATE(), INTERVAL -2 MONTH)), + (10, 10, 16, 19, DATE_ADD(CURDATE(), INTERVAL -3 MONTH)), (11, 11, 3 , 19, CURDATE()), (12, 12, 3 , 19, CURDATE()), (13, 13, 3 , 19, CURDATE()), @@ -519,18 +522,18 @@ INSERT INTO `vn`.`ticketPackaging`(`id`, `ticketFk`, `packagingFk`, `quantity`, INSERT INTO `vn`.`sale`(`id`, `itemFk`, `ticketFk`, `concept`, `quantity`, `price`, `discount`, `reserved`, `isPicked`, `created`) VALUES - ( 1, 1, 1 , 'Gem of Time', 5 , 11.42, 0, 0, 0, CURDATE()), - ( 2, 2, 1 , 'Gem of Mind', 10 , 1.30, 0, 0, 0, CURDATE()), - ( 3, 1, 1 , 'Gem of Time', 2 , 11.42, 0, 0, 0, CURDATE()), - ( 4, 4, 1 , 'Mark I' , 20 , 3.26, 0, 0, 0, CURDATE()), - ( 5, 1, 2 , 'Gem of Time', 10 , 11.42, 0, 0, 0, CURDATE()), - ( 6, 1, 3 , 'Gem of Time', 15 , 11.42, 0, 0, 0, CURDATE()), - ( 7, 2, 11, 'Gem of Mind', 15 , 1.30, 0, 0, 0, CURDATE()), - ( 8, 4, 11, 'Mark I' , 10 , 3.26, 0, 0, 0, CURDATE()), - ( 9, 1, 16, 'Gem of Time', 5 , 11.42, 0, 0, 0, CURDATE()), - ( 10, 2, 16, 'Gem of Mind', 10 , 1.30, 0, 0, 0, CURDATE()), - ( 11, 1, 16, 'Gem of Time', 2 , 11.42, 0, 0, 0, CURDATE()), - ( 12, 4, 16, 'Mark I' , 20 , 3.26, 0, 0, 0, CURDATE()); + ( 1, 1, 1 , 'Gem of Time', 5, 9.10, 0, 0, 0, CURDATE()), + ( 2, 2, 1 , 'Gem of Mind', 10, 1.07, 0, 0, 0, CURDATE()), + ( 3, 1, 1 , 'Gem of Time', 2, 9.10, 0, 0, 0, CURDATE()), + ( 4, 4, 1 , 'Mark I' , 20, 3.06, 0, 0, 0, CURDATE()), + ( 5, 1, 2 , 'Gem of Time', 10, 9.10, 0, 0, 0, CURDATE()), + ( 6, 1, 3 , 'Gem of Time', 15, 6.50, 0, 0, 0, CURDATE()), + ( 7, 2, 11, 'Gem of Mind', 15, 1.30, 0, 0, 0, CURDATE()), + ( 8, 4, 11, 'Mark I' , 10, 3.26, 0, 0, 0, CURDATE()), + ( 9, 1, 16, 'Gem of Time', 5, 9.10, 0, 0, 0, CURDATE()), + ( 10, 2, 16, 'Gem of Mind', 10, 1.07, 0, 0, 0, CURDATE()), + ( 11, 1, 16, 'Gem of Time', 2, 9.10, 0, 0, 0, CURDATE()), + ( 12, 4, 16, 'Mark I' , 20, 3.06, 0, 0, 0, CURDATE()); INSERT INTO `vn`.`saleChecked`(`saleFk`, `isChecked`) VALUES @@ -539,68 +542,64 @@ INSERT INTO `vn`.`saleChecked`(`saleFk`, `isChecked`) INSERT INTO `vn`.`saleComponent`(`saleFk`, `componentFk`, `value`) VALUES - ( 1, 10, 1), - ( 1, 14, 2.5), - ( 1, 15, 3), - ( 1, 17, 4.5), - ( 1, 21, 5), - ( 1, 23, 6.5), - ( 1, 28, 1), - ( 2, 28, 1), - ( 3, 10, 1), - ( 3, 14, 2.5), - ( 3, 15, 3), - ( 3, 17, 4.5), - ( 3, 21, 5), - ( 3, 23, 6.5), - ( 3, 28, 1), - ( 4, 28, 1), - ( 4, 10, 1), - ( 2, 17, 3.5), - ( 4, 39, 5), - ( 4, 37, 2), - ( 5, 10, 1), - ( 5, 14, 2.5), - ( 5, 15, 3), - ( 5, 17, 4.5), - ( 5, 21, 5), - ( 5, 23, 6.5), - ( 5, 28, 1), - ( 6, 10, 1), - ( 6, 14, 2.5), - ( 6, 15, 3), - ( 6, 17, 4.5), - ( 6, 21, 5), - ( 6, 23, 6.5), - ( 6, 28, 1), - ( 7, 28, 1), - ( 7, 17, 3.5), - ( 7, 15, 3), - ( 8, 28, 1), - ( 8, 10, 1), - ( 8, 39, 5), - ( 8, 15, 5), - ( 8, 37, 2), - ( 9, 10, 1), - ( 9, 14, 2.5), - ( 9, 15, 3), - ( 9, 17, 4.5), - ( 9, 21, 5), - ( 9, 23, 6.5), - ( 9, 28, 1), - ( 10, 28, 1), - ( 11, 10, 1), - ( 11, 14, 2.5), - ( 11, 15, 3), - ( 11, 17, 4.5), - ( 11, 21, 5), - ( 11, 23, 6.5), - ( 11, 28, 1), - ( 12, 28, 1), - ( 12, 10, 1), - ( 10, 17, 3.5), - ( 12, 39, 5), - ( 12, 37, 2); + ( 1, 15, 0.58), + ( 1, 23, 6.5), + ( 1, 28, 20.72), + ( 1, 29, -18.72), + ( 1, 39, 0.02), + ( 2, 15, 0.058), + ( 2, 21, 0.002), + ( 2, 28, 5.6), + ( 2, 29, -4.6), + ( 2, 39, 0.01), + ( 3, 15, 0.58), + ( 3, 23, 6.5), + ( 3, 28, 20.72), + ( 3, 29, -18.72), + ( 3, 39, 0.02), + ( 4, 15, 0.051), + ( 4, 21, -0.001), + ( 4, 28, 20.72), + ( 4, 29, -19.72), + ( 4, 37, 2), + ( 4, 39, 0.01), + ( 5, 15, 0.58), + ( 5, 23, 6.5), + ( 5, 28, 20.72), + ( 5, 29, -18.72), + ( 5, 39, 0.02), + ( 6, 23, 6.5), + ( 7, 15, 0.29), + ( 7, 28, 5.6), + ( 7, 29, -4.6), + ( 7, 39, 0.01), + ( 8, 15, 0.254), + ( 8, 21, -0.004), + ( 8, 28, 20.72), + ( 8, 29, -19.72), + ( 8, 37, 2), + ( 8, 39, 0.01), + ( 9, 15, 0.58), + ( 9, 23, 6.5), + ( 9, 28, 20.72), + ( 9, 29, -18.72), + ( 9, 39, 0.02), + ( 10, 15, 0.058), + ( 10, 21, 0.002), + ( 10, 28, 5.6), + ( 10, 29, -4.6), + ( 10, 39, 0.01), + ( 11, 15, 0.58), + ( 11, 23, 6.5), + ( 11, 28, 20.72), + ( 11, 29, -18.72), + ( 11, 39, 0.02), + ( 12, 15, 0.051), + ( 12, 22, -0.001), + ( 12, 28, 20.72), + ( 12, 29, -19.72), + ( 12, 37, 2), + ( 12, 39, 0.01); INSERT INTO `vn`.`saleTracking`(`saleFk`, `isChecked`, `created`, `originalQuantity`, `workerFk`, `actionFk`, `id`, `stateFk`) VALUES @@ -867,4 +866,4 @@ INSERT INTO `vn`.`claimEnd`(`id`, `saleFk`, `claimFk`, `workerFk`, `claimDestina ( 1, 1, 1, 9, 5), ( 2, 2, 1, 9, 5), ( 3, 5, 2, 9, 5), - ( 4, 6, 3, 9, 5); \ No newline at end of file + ( 4, 6, 3, 9, 5); diff --git a/services/loopback/common/locale/en.json b/services/loopback/common/locale/en.json index 909aecb09..25e410536 100644 --- a/services/loopback/common/locale/en.json +++ b/services/loopback/common/locale/en.json @@ -31,6 +31,8 @@ "Sample type cannot be blank": "Sample type cannot be blank", "The package cannot be blank": "The package cannot be blank", "The warehouse can't be repeated": "The warehouse can't be repeated", - "The sales of that ticket can't be modified": "The sales of that ticket can't be modified", - "The new quantity should be smaller than the old one": "The new quantity should be smaller than the old one" + "The new quantity should be smaller than the old one": "The new quantity should be smaller than the old one", + "Package cannot be blank": "Package cannot be blank", + "The sales of this ticket can't be modified": "The sales of this ticket can't be modified", + "You don't have enough privileges to do that": "You don't have enough privileges to do that" } \ No newline at end of file diff --git a/services/loopback/common/methods/client/specs/addressesPropagateRe.spec.js b/services/loopback/common/methods/client/specs/addressesPropagateRe.spec.js index 077fbe95a..e9d3b26a2 100644 --- a/services/loopback/common/methods/client/specs/addressesPropagateRe.spec.js +++ b/services/loopback/common/methods/client/specs/addressesPropagateRe.spec.js @@ -1,20 +1,17 @@ const app = require(`${servicesDir}/client/server/server`); -const restoreFixtures = require(`${servicesDir}/db/testing_fixtures`); describe('Client addressesPropagateRe', () => { - let sqlStatements = {deletes: ``, inserts: ``, updates: - `UPDATE vn.address SET isEqualizated = FALSE WHERE clientFk = 101; - UPDATE vn.client SET hasToInvoiceByAddress = TRUE WHERE id = 101;` - }; - beforeEach(() => { - restoreFixtures(sqlStatements); + beforeEach(async() => { + await app.models.Address.update({clientFk: 101}, {isEqualizated: false}); + await app.models.Client.update({id: 101}, {hasToInvoiceByAddress: true}); }); - afterAll(() => { - restoreFixtures(sqlStatements); + afterAll(async() => { + await app.models.Address.update({clientFk: 101}, {isEqualizated: false}); + await app.models.Client.update({id: 101}, {hasToInvoiceByAddress: true}); }); - it('should propagate the isEqualizated on both addresses of Mr Wayne and set hasToInvoiceByAddress to false', async () => { + it('should propagate the isEqualizated on both addresses of Mr Wayne and set hasToInvoiceByAddress to false', async() => { let id = 101; let data = { isEqualizated: true diff --git a/services/loopback/common/methods/client/specs/getCard.spec.js b/services/loopback/common/methods/client/specs/getCard.spec.js index 6b5f0e2b7..5d80e7eaa 100644 --- a/services/loopback/common/methods/client/specs/getCard.spec.js +++ b/services/loopback/common/methods/client/specs/getCard.spec.js @@ -7,6 +7,6 @@ describe('Client card', () => { expect(result.id).toEqual(101); expect(result.name).toEqual('Bruce Wayne'); - expect(result.debt).toEqual(1048.76); + expect(result.debt).toEqual(972.78); }); }); diff --git a/services/loopback/common/methods/client/specs/getDebt.spec.js b/services/loopback/common/methods/client/specs/getDebt.spec.js index e406f16e6..8814d3b99 100644 --- a/services/loopback/common/methods/client/specs/getDebt.spec.js +++ b/services/loopback/common/methods/client/specs/getDebt.spec.js @@ -4,7 +4,7 @@ describe('client getDebt()', () => { it('should return the client debt', async() => { let result = await app.models.Client.getDebt(101); - expect(result.debt).toEqual(1048.76); + expect(result.debt).toEqual(972.78); }); }); diff --git a/services/loopback/common/methods/client/specs/getMana.spec.js b/services/loopback/common/methods/client/specs/getMana.spec.js index 8a3b6ff2d..1b621faab 100644 --- a/services/loopback/common/methods/client/specs/getMana.spec.js +++ b/services/loopback/common/methods/client/specs/getMana.spec.js @@ -4,7 +4,7 @@ describe('client getMana()', () => { it('should call the getMana method', async() => { let result = await app.models.Client.getMana(101); - expect(result.mana).toEqual(400); + expect(result.mana).toEqual(151.33); }); }); diff --git a/services/loopback/common/methods/client/specs/summary.spec.js b/services/loopback/common/methods/client/specs/summary.spec.js index 4e3c7cec7..b11e9d8a2 100644 --- a/services/loopback/common/methods/client/specs/summary.spec.js +++ b/services/loopback/common/methods/client/specs/summary.spec.js @@ -11,13 +11,13 @@ describe('client summary()', () => { it('should return a summary object containing mana', async() => { let result = await app.models.Client.summary(101); - expect(result.mana.mana).toEqual(400); + expect(result.mana.mana).toEqual(151.33); }); it('should return a summary object containing debt', async() => { let result = await app.models.Client.summary(101); - expect(result.debt.debt).toEqual(1048.76); + expect(result.debt.debt).toEqual(972.78); }); it('should return a summary object containing averageInvoiced', async() => { diff --git a/services/loopback/common/methods/sale/moveToTicket.js b/services/loopback/common/methods/sale/moveToTicket.js index 254ad859e..e8a57a22b 100644 --- a/services/loopback/common/methods/sale/moveToTicket.js +++ b/services/loopback/common/methods/sale/moveToTicket.js @@ -28,7 +28,7 @@ module.exports = Self => { let newTicketIsEditable = await Self.app.models.Ticket.isEditable(params.newTicketFk); if (!newTicketIsEditable) - throw new UserError(`The sales of that ticket can't be modified`); + throw new UserError(`The sales of this ticket can't be modified`); for (let i = 0; i < params.sales.length; i++) { await Self.app.models.Sale.update({id: params.sales[i].id}, {ticketFk: params.newTicketFk}); diff --git a/services/loopback/common/methods/sale/reserve.js b/services/loopback/common/methods/sale/reserve.js index 9d3761c47..7a657020c 100644 --- a/services/loopback/common/methods/sale/reserve.js +++ b/services/loopback/common/methods/sale/reserve.js @@ -9,7 +9,7 @@ module.exports = Self => { arg: 'params', type: 'object', required: true, - description: '[sales IDs], actualTicketFk, reserved', + description: '[sales IDs], ticketFk, reserved', http: {source: 'body'} }], returns: { @@ -23,7 +23,7 @@ module.exports = Self => { }); Self.reserve = async params => { - let thisTicketIsEditable = await Self.app.models.Ticket.isEditable(params.actualTicketFk); + let thisTicketIsEditable = await Self.app.models.Ticket.isEditable(params.ticketFk); if (!thisTicketIsEditable) throw new UserError(`The sales of this ticket can't be modified`); diff --git a/services/loopback/common/methods/sale/specs/moveToTicket.spec.js b/services/loopback/common/methods/sale/specs/moveToTicket.spec.js index b16f3b992..a20b28e79 100644 --- a/services/loopback/common/methods/sale/specs/moveToTicket.spec.js +++ b/services/loopback/common/methods/sale/specs/moveToTicket.spec.js @@ -22,62 +22,58 @@ describe('sale moveToTicket()', () => { await app.models.Sale.moveToTicket(params) .catch(response => { - expect(response.message).toEqual(`The sales of that ticket can't be modified`); + expect(response.message).toEqual(`The sales of this ticket can't be modified`); error = response; }); expect(error).toBeDefined(); }); - it('should transfer the sales from ticket 1 to ticket 13', async() => { - let senderTicketSales = await app.models.Ticket.getSales(1); + it('should transfer the sales from one ticket to another', async() => { + let senderTicketSales = await app.models.Ticket.getSales(11); let receiverTicketSales = await app.models.Ticket.getSales(13); - expect(senderTicketSales.length).toEqual(4); + expect(senderTicketSales.length).toEqual(2); expect(receiverTicketSales.length).toEqual(0); let params = { - actualTicketFk: 1, + actualTicketFk: 11, newTicketFk: 13, sales: [ - {id: 1}, - {id: 2}, - {id: 3}, - {id: 4}] + {id: 7}, + {id: 8}] }; await app.models.Sale.moveToTicket(params); - senderTicketSales = await app.models.Ticket.getSales(1); + senderTicketSales = await app.models.Ticket.getSales(11); receiverTicketSales = await app.models.Ticket.getSales(13); expect(senderTicketSales.length).toEqual(0); - expect(receiverTicketSales.length).toEqual(4); + expect(receiverTicketSales.length).toEqual(2); }); - it('should transfer the sales back from ticket 13 to ticket 1', async() => { + it('should transfers back the sales', async() => { let senderTicketSales = await app.models.Ticket.getSales(13); - let receiverTicketSales = await app.models.Ticket.getSales(1); + let receiverTicketSales = await app.models.Ticket.getSales(11); - expect(senderTicketSales.length).toEqual(4); + expect(senderTicketSales.length).toEqual(2); expect(receiverTicketSales.length).toEqual(0); let params = { actualTicketFk: 13, - newTicketFk: 1, + newTicketFk: 11, sales: [ - {id: 1}, - {id: 2}, - {id: 3}, - {id: 4}] + {id: 7}, + {id: 8}] }; await app.models.Sale.moveToTicket(params); senderTicketSales = await app.models.Ticket.getSales(13); - receiverTicketSales = await app.models.Ticket.getSales(1); + receiverTicketSales = await app.models.Ticket.getSales(11); expect(senderTicketSales.length).toEqual(0); - expect(receiverTicketSales.length).toEqual(4); + expect(receiverTicketSales.length).toEqual(2); }); }); diff --git a/services/loopback/common/methods/sale/specs/priceDifference.spec.js b/services/loopback/common/methods/sale/specs/priceDifference.spec.js index dc562ee57..5806a5c4d 100644 --- a/services/loopback/common/methods/sale/specs/priceDifference.spec.js +++ b/services/loopback/common/methods/sale/specs/priceDifference.spec.js @@ -10,8 +10,8 @@ describe('sale priceDifference()', () => { }; let result = await app.models.Sale.priceDifference(1, data); - expect(result.totalUnitPrice).toEqual(27.4); + expect(result.totalUnitPrice).toEqual(22.33); expect(result.totalNewPrice).toEqual(22.33); - expect(result.totalDifference).toEqual(22.54); + expect(result.totalDifference).toEqual(0); }); }); diff --git a/services/loopback/common/methods/sale/specs/reserve.spec.js b/services/loopback/common/methods/sale/specs/reserve.spec.js index 79f2dcfe6..74f4961aa 100644 --- a/services/loopback/common/methods/sale/specs/reserve.spec.js +++ b/services/loopback/common/methods/sale/specs/reserve.spec.js @@ -4,11 +4,9 @@ describe('sale reserve()', () => { afterAll(async() => { let params = { sales: [ - {id: 1}, - {id: 2}, - {id: 3}, - {id: 4}], - ticketFk: 1, + {id: 7}, + {id: 8}], + ticketFk: 11, reserved: false }; @@ -17,7 +15,9 @@ describe('sale reserve()', () => { it('should throw an error if the ticket can not be modified', async() => { let error; - let params = {actualTicketFk: 10, sales: [{id: 4, instance: 3}]}; + let params = {ticketFk: 2, + sales: [{id: 5}], + reserved: false}; await app.models.Sale.reserve(params) .catch(response => { @@ -28,31 +28,25 @@ describe('sale reserve()', () => { expect(error).toBeDefined(); }); - it('should update the given sales of a ticket as reserved', async() => { - originalTicketSales = await app.models.Ticket.getSales(1); + it('should update the given sales of a ticket to reserved', async() => { + originalTicketSales = await app.models.Ticket.getSales(11); expect(originalTicketSales[0].reserved).toEqual(0); expect(originalTicketSales[1].reserved).toEqual(0); - expect(originalTicketSales[2].reserved).toEqual(0); - expect(originalTicketSales[3].reserved).toEqual(0); let params = { sales: [ - {id: 1}, - {id: 2}, - {id: 3}, - {id: 4}], - ticketFk: 1, + {id: 7}, + {id: 8}], + ticketFk: 11, reserved: true }; await app.models.Sale.reserve(params); - let reservedTicketSales = await app.models.Ticket.getSales(1); + let reservedTicketSales = await app.models.Ticket.getSales(11); expect(reservedTicketSales[0].reserved).toEqual(1); expect(reservedTicketSales[1].reserved).toEqual(1); - expect(reservedTicketSales[2].reserved).toEqual(1); - expect(reservedTicketSales[3].reserved).toEqual(1); }); }); diff --git a/services/loopback/common/methods/ticket/specs/componentUpdate.spec.js b/services/loopback/common/methods/ticket/specs/componentUpdate.spec.js index 4b00264b6..303d90db9 100644 --- a/services/loopback/common/methods/ticket/specs/componentUpdate.spec.js +++ b/services/loopback/common/methods/ticket/specs/componentUpdate.spec.js @@ -1,21 +1,76 @@ const app = require(`${servicesDir}/ticket/server/server`); -xdescribe('ticket componentUpdate()', () => { - it('should call the componentUpdate method and receive an error', async() => { +describe('ticket componentUpdate()', () => { + let firstvalueBeforeChange; + let secondvalueBeforeChange; + let componentOfSaleSeven = `SELECT value FROM vn.saleComponent + WHERE saleFk = 7 AND componentFk = 15`; + + let componentOfSaleEight = `SELECT value FROM vn.saleComponent + WHERE saleFk = 8 AND componentFk = 15`; + const toDay = new Date(); + + beforeAll(async() => { + [componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleSeven); + firstvalueBeforeChange = componentValue.value; + + [componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleEight); + secondvalueBeforeChange = componentValue.value; + }); + + it('should change the agencyMode to modify the sale components value', async() => { + let firstvalueAfterChange; + let secondvalueAfterChange; let data = { clientFk: 101, - agencyModeFk: 1, + agencyModeFk: 8, addressFk: 121, warehouseFk: 1, - shipped: new Date(), - landed: new Date(), + shipped: toDay, + landed: toDay, isDeleted: false, hasToBeUnrouted: false, option: 1 }; - let ctx = {req: {accessToken: {userId: 101}}}; - let result = await app.models.Ticket.componentUpdate(1, data, ctx); - expect(result.constructor.name).toEqual('OkPacket'); + let ctx = {req: {accessToken: {userId: 101}}}; + await app.models.Ticket.componentUpdate(11, data, ctx); + + [componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleSeven); + firstvalueAfterChange = componentValue.value; + + [componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleEight); + secondvalueAfterChange = componentValue.value; + + expect(firstvalueBeforeChange).not.toEqual(firstvalueAfterChange); + expect(secondvalueBeforeChange).not.toEqual(secondvalueAfterChange); + }); + + it('should change the agencyMode to go back to the originals sale components value', async() => { + let firstvalueAfterChange; + let secondvalueAfterChange; + let data = { + clientFk: 101, + agencyModeFk: 7, + addressFk: 121, + warehouseFk: 1, + shipped: toDay, + landed: toDay, + isDeleted: false, + hasToBeUnrouted: false, + option: 1 + }; + + let ctx = {req: {accessToken: {userId: 101}}}; + await app.models.Ticket.componentUpdate(11, data, ctx); + + [componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleSeven); + firstvalueAfterChange = componentValue.value; + + [componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleEight); + secondvalueAfterChange = componentValue.value; + + expect(firstvalueBeforeChange).toEqual(firstvalueAfterChange); + expect(secondvalueBeforeChange).toEqual(secondvalueAfterChange); }); }); diff --git a/services/loopback/common/methods/ticket/specs/getSalespersonMana.spec.js b/services/loopback/common/methods/ticket/specs/getSalespersonMana.spec.js index f0b695528..16cd70e39 100644 --- a/services/loopback/common/methods/ticket/specs/getSalespersonMana.spec.js +++ b/services/loopback/common/methods/ticket/specs/getSalespersonMana.spec.js @@ -4,7 +4,7 @@ describe('ticket getSalesPersonMana()', () => { it('should get the mana of a salesperson of a given ticket', async() => { let mana = await app.models.Ticket.getSalesPersonMana(1); - expect(mana).toEqual(470); + expect(mana).toEqual(221); }); it('should return 0 if the given ticket does not exists', async() => { diff --git a/services/loopback/common/methods/ticket/specs/getTaxes.spec.js b/services/loopback/common/methods/ticket/specs/getTaxes.spec.js index feab81459..9a3b58175 100644 --- a/services/loopback/common/methods/ticket/specs/getTaxes.spec.js +++ b/services/loopback/common/methods/ticket/specs/getTaxes.spec.js @@ -4,6 +4,6 @@ describe('ticket getTaxes()', () => { it('should return the tax of a given ticket', async() => { let result = await app.models.Ticket.getTaxes(1); - expect(result[0].tax).toEqual(9.29); + expect(result[0].tax).toEqual(7.44); }); }); diff --git a/services/loopback/common/methods/ticket/specs/getTotal.spec.js b/services/loopback/common/methods/ticket/specs/getTotal.spec.js index b80ff3d97..89ac0ac2d 100644 --- a/services/loopback/common/methods/ticket/specs/getTotal.spec.js +++ b/services/loopback/common/methods/ticket/specs/getTotal.spec.js @@ -4,7 +4,7 @@ describe('ticket getTotal()', () => { it('should return the total of a ticket', async() => { let result = await app.models.Ticket.getTotal(1); - expect(result).toEqual(181.12); + expect(result).toEqual(155.89); }); it(`should return zero if the ticket doesn't have lines`, async() => { diff --git a/services/loopback/common/methods/ticket/specs/getVAT.spec.js b/services/loopback/common/methods/ticket/specs/getVAT.spec.js index 629452376..e03d275d8 100644 --- a/services/loopback/common/methods/ticket/specs/getVAT.spec.js +++ b/services/loopback/common/methods/ticket/specs/getVAT.spec.js @@ -4,7 +4,7 @@ describe('ticket getVAT()', () => { it('should call the getVAT method and return the response', async() => { await app.models.Ticket.getVAT(1) .then(response => { - expect(response).toEqual(22.98); + expect(response).toEqual(20.29); }); }); diff --git a/services/loopback/common/methods/ticket/specs/summary.spec.js b/services/loopback/common/methods/ticket/specs/summary.spec.js index 9abb0fecd..f2ec4632b 100644 --- a/services/loopback/common/methods/ticket/specs/summary.spec.js +++ b/services/loopback/common/methods/ticket/specs/summary.spec.js @@ -17,13 +17,13 @@ describe('ticket summary()', () => { it('should return a summary object containing subTotal for 1 ticket', async() => { let result = await app.models.Ticket.summary(1); - expect(result.subTotal).toEqual(158.14); + expect(Math.round(result.subTotal * 100) / 100).toEqual(135.60); }); it('should return a summary object containing VAT for 1 ticket', async() => { let result = await app.models.Ticket.summary(1); - expect(Math.round(result.VAT * 100) / 100).toEqual(22.98); + expect(Math.round(result.VAT * 100) / 100).toEqual(20.29); }); it('should return a summary object containing total for 1 ticket', async() => { diff --git a/services/loopback/common/methods/workerMana/specs/getCurrentWorkerMana.spec.js b/services/loopback/common/methods/workerMana/specs/getCurrentWorkerMana.spec.js index 73d51c6a0..7f67757fd 100644 --- a/services/loopback/common/methods/workerMana/specs/getCurrentWorkerMana.spec.js +++ b/services/loopback/common/methods/workerMana/specs/getCurrentWorkerMana.spec.js @@ -4,7 +4,7 @@ describe('workerMana getCurrentWorkerMana()', () => { it('should get the mana of the logged worker', async() => { let mana = await app.models.WorkerMana.getCurrentWorkerMana({req: {accessToken: {userId: 18}}}); - expect(mana).toEqual(470); + expect(mana).toEqual(221); }); it('should return 0 if the user doesnt uses mana', async() => { diff --git a/services/order/common/methods/order/specs/getTaxes.spec.js b/services/order/common/methods/order/specs/getTaxes.spec.js index 867714774..4d8b30c27 100644 --- a/services/order/common/methods/order/specs/getTaxes.spec.js +++ b/services/order/common/methods/order/specs/getTaxes.spec.js @@ -1,6 +1,6 @@ const app = require(`${servicesDir}/order/server/server`); -xdescribe('order getTaxes()', () => { +describe('order getTaxes()', () => { it('should call the getTaxes method and return undefined if its called with a string', async() => { let result = await app.models.Order.getTaxes('pepinillos'); diff --git a/services/order/common/methods/order/specs/getTotal.spec.js b/services/order/common/methods/order/specs/getTotal.spec.js index 083ee6d50..52681a0b1 100644 --- a/services/order/common/methods/order/specs/getTotal.spec.js +++ b/services/order/common/methods/order/specs/getTotal.spec.js @@ -1,6 +1,6 @@ const app = require(`${servicesDir}/order/server/server`); -xdescribe('order getTotal()', () => { +describe('order getTotal()', () => { it('should return the total', async() => { let result = await app.models.Order.getTotal(1); From 564370180c7371a6ca5d42d8f90b137befc8a6fe Mon Sep 17 00:00:00 2001 From: Joan Date: Mon, 24 Sep 2018 10:43:54 +0200 Subject: [PATCH 6/8] zone basic data --- .../core/src/components/input-time/index.js | 19 +++--- .../core/src/components/input-time/style.scss | 2 +- client/core/src/components/watcher/watcher.js | 16 +++-- client/core/src/lib/modified.js | 8 ++- client/route/src/zone/basic-data/index.html | 67 +++++++++++++++++++ client/route/src/zone/basic-data/index.js | 27 ++++++++ .../db/install/changes/1.1.1/zoneChanges.sql | 19 +++++- services/route/common/models/zone.json | 2 +- 8 files changed, 138 insertions(+), 22 deletions(-) create mode 100644 client/route/src/zone/basic-data/index.html create mode 100644 client/route/src/zone/basic-data/index.js diff --git a/client/core/src/components/input-time/index.js b/client/core/src/components/input-time/index.js index 0b5a8fcbd..e8e064032 100644 --- a/client/core/src/components/input-time/index.js +++ b/client/core/src/components/input-time/index.js @@ -4,18 +4,19 @@ import './style.scss'; export default class InputTime extends Textfield { - constructor($element, $scope, $attrs, vnTemplate, $transclude, $filter) { - super($element, $scope, $attrs, vnTemplate, $transclude); - - this.$filter = $filter; - } - get value() { return this._value; } set value(value) { - this._value = value; + if (!value) return; + + let newDate = new Date(value); + newDate.setSeconds(0); + newDate.setMilliseconds(0); + + this._value = newDate; + this.hasValue = this._value !== null; if (this.hasValue) this.element.classList.add('not-empty'); @@ -24,7 +25,7 @@ export default class InputTime extends Textfield { } get step() { - return parseFloat(this.input.step); + return parseInt(this.input.step); } set step(value) { @@ -32,7 +33,7 @@ export default class InputTime extends Textfield { } } -InputTime.$inject = ['$element', '$scope', '$attrs', 'vnTemplate', '$transclude', '$filter']; +InputTime.$inject = ['$element', '$scope', '$attrs', 'vnTemplate', '$transclude']; ngModule.component('vnInputTime', { template: require('./index.html'), diff --git a/client/core/src/components/input-time/style.scss b/client/core/src/components/input-time/style.scss index 3b7333f9b..94ec6cbf3 100644 --- a/client/core/src/components/input-time/style.scss +++ b/client/core/src/components/input-time/style.scss @@ -3,7 +3,7 @@ vn-input-time { @extend vn-textfield; - + input[type="time"] { clip-path: inset(0 17px 0 0); outline:none; diff --git a/client/core/src/components/watcher/watcher.js b/client/core/src/components/watcher/watcher.js index 5d2f4b096..36b3dc333 100644 --- a/client/core/src/components/watcher/watcher.js +++ b/client/core/src/components/watcher/watcher.js @@ -223,13 +223,15 @@ export default class Watcher extends Component { let newCopy = {}; if (data && typeof data === 'object') { Object.keys(data).forEach( - val => { - if (!isFullEmpty(data[val])) { - if (typeof data[val] === 'object') { - newCopy[val] = this.copyInNewObject(data[val]); - } else { - newCopy[val] = data[val]; - } + key => { + let value = data[key]; + if (value instanceof Date) + newCopy[key] = new Date(value.getTime()); + else if (!isFullEmpty(value)) { + if (typeof value === 'object') + newCopy[key] = this.copyInNewObject(value); + else + newCopy[key] = value; } } ); diff --git a/client/core/src/lib/modified.js b/client/core/src/lib/modified.js index f142126fb..46e61b4f5 100644 --- a/client/core/src/lib/modified.js +++ b/client/core/src/lib/modified.js @@ -2,15 +2,17 @@ import isEqual from './equals'; export default function getModifiedData(object, objectOld) { var newObject = {}; - if (objectOld === null) { + if (objectOld === null) return object; - } + for (var k in object) { var val = object[k]; var valOld = objectOld[k] === undefined ? null : objectOld[k]; if (!isEqual(val, valOld)) { - if (val instanceof Object) { + if (val instanceof Date) { + newObject[k] = new Date(val.getTime()); + } else if (val instanceof Object) { newObject[k] = getModifiedData(val, valOld); } else { newObject[k] = val; diff --git a/client/route/src/zone/basic-data/index.html b/client/route/src/zone/basic-data/index.html new file mode 100644 index 000000000..0bf5a8efb --- /dev/null +++ b/client/route/src/zone/basic-data/index.html @@ -0,0 +1,67 @@ + + + +
+ + Basic data + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/client/route/src/zone/basic-data/index.js b/client/route/src/zone/basic-data/index.js new file mode 100644 index 000000000..b19194084 --- /dev/null +++ b/client/route/src/zone/basic-data/index.js @@ -0,0 +1,27 @@ +import ngModule from '../../module'; + +class Controller { + + constructor($scope) { + this.$scope = $scope; + } + + onSubmit() { + this.$scope.watcher.submit().then(() => { + this.card.reload(); + }); + } +} + +Controller.$inject = ['$scope']; + +ngModule.component('vnZoneBasicData', { + template: require('./index.html'), + controller: Controller, + bindings: { + zone: '<' + }, + require: { + card: '^vnZoneCard' + } +}); diff --git a/services/db/install/changes/1.1.1/zoneChanges.sql b/services/db/install/changes/1.1.1/zoneChanges.sql index f04619106..d533bce65 100644 --- a/services/db/install/changes/1.1.1/zoneChanges.sql +++ b/services/db/install/changes/1.1.1/zoneChanges.sql @@ -5,4 +5,21 @@ ALTER TABLE `vn`.`zoneNest` RENAME TO `vn`.`zoneGeo` ; ALTER TABLE `vn`.`zone` -CHANGE COLUMN `agencyFk` `agencyModeFk` INT(11) NOT NULL ; +CHANGE COLUMN `agencyFk` `agencyModeFk` INT(11) NOT NULL, +CHANGE COLUMN `hour` `hour` DATETIME NOT NULL, +CHANGE COLUMN `warehouseFk` `warehouseFk` SMALLINT(6) UNSIGNED NOT NULL ; + +ALTER TABLE `vn`.`zone` +ADD INDEX `fk_zone_1_idx` (`warehouseFk` ASC), +ADD INDEX `fk_zone_2_idx` (`agencyModeFk` ASC); +ALTER TABLE `vn`.`zone` +ADD CONSTRAINT `fk_zone_1` + FOREIGN KEY (`warehouseFk`) + REFERENCES `vn2008`.`warehouse` (`id`) + ON DELETE NO ACTION + ON UPDATE CASCADE, +ADD CONSTRAINT `fk_zone_2` + FOREIGN KEY (`agencyModeFk`) + REFERENCES `vn2008`.`Agencias` (`Id_Agencia`) + ON DELETE NO ACTION + ON UPDATE NO ACTION; diff --git a/services/route/common/models/zone.json b/services/route/common/models/zone.json index 70f9c4e39..5c297f766 100644 --- a/services/route/common/models/zone.json +++ b/services/route/common/models/zone.json @@ -16,7 +16,7 @@ "required": true }, "hour": { - "type": "Date", + "type": "date", "required": true }, "travelingDays": { From 0b5a0754fd968c64ed2fb2dfcaf73df4bedadb2d Mon Sep 17 00:00:00 2001 From: Joan Date: Mon, 24 Sep 2018 11:10:03 +0200 Subject: [PATCH 7/8] searchbar with icons #371 --- .../src/components/searchbar/searchbar.html | 30 +++++++++++-------- .../core/src/components/textfield/style.scss | 11 +++++++ e2e/helpers/selectors.js | 8 ++--- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/client/core/src/components/searchbar/searchbar.html b/client/core/src/components/searchbar/searchbar.html index 9bc053f1b..61132d5c0 100644 --- a/client/core/src/components/searchbar/searchbar.html +++ b/client/core/src/components/searchbar/searchbar.html @@ -1,18 +1,22 @@
- - - - - + + + + + + + + + +
[icon="icon-clone"]`, acceptClonationAlertButton: `vn-item-index [vn-id="clone"] [response="ACCEPT"]`, searchItemInput: `${components.vnTextfield}`, - searchButton: `vn-searchbar vn-icon-button[icon="search"]`, + searchButton: `vn-searchbar vn-icon[icon="search"]`, closeItemSummaryPreview: 'vn-item-index [vn-id="preview"] button.close' }, itemCreateView: { @@ -278,7 +278,7 @@ export default { searchResultDate: `vn-ticket-index vn-table vn-tbody > a:nth-child(1) > vn-td:nth-child(4)`, searchResultAddress: `vn-ticket-index vn-table vn-tbody > a:nth-child(1) > vn-td:nth-child(6)`, searchTicketInput: `vn-ticket-index ${components.vnTextfield}`, - searchButton: `vn-ticket-index vn-searchbar vn-icon-button[icon="search"]` + searchButton: `vn-ticket-index vn-searchbar vn-icon[icon="search"]` }, ticketNotes: { notesButton: `vn-menu-item a[ui-sref="ticket.card.observation"]`, @@ -384,7 +384,7 @@ export default { claimsIndex: { searchClaimInput: `vn-claim-index ${components.vnTextfield}`, searchResult: `vn-claim-index vn-card > div > vn-table > div > vn-tbody > vn-tr`, - searchButton: `vn-claim-index vn-searchbar > form > vn-horizontal > vn-icon-button > vn-icon` + searchButton: `vn-claim-index vn-searchbar vn-icon[icon="search"]` }, claimBasicData: { basicDataButton: `vn-menu-item a[ui-sref="claim.card.basicData"]`, From 79737fc508c9543636b57f9debdac316efc453d9 Mon Sep 17 00:00:00 2001 From: Bernat Date: Mon, 24 Sep 2018 12:03:01 +0200 Subject: [PATCH 8/8] update fixtures --- services/db/install/dump/fixtures.sql | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/services/db/install/dump/fixtures.sql b/services/db/install/dump/fixtures.sql index c9ab1f4a8..1502739ea 100644 --- a/services/db/install/dump/fixtures.sql +++ b/services/db/install/dump/fixtures.sql @@ -68,17 +68,17 @@ INSERT INTO `vn`.`bank`(`id`, `bank`, `account`, `cash`, `entityFk`, `isActive`) VALUES (8, 'Pay on receipt', '0000000000', 4, 0, 1); -INSERT INTO `vn`.`agency`(`id`, `name`, `warehouseFk`, `isVolumetric`, `bankFk`, `warehouseAliasFk`) +INSERT INTO `vn`.`agency`(`id`, `name`, `warehouseFk`, `isVolumetric`, `bankFk`, `warehouseAliasFk`, `code`) VALUES - (1, 'inhouse pickup' , 1, 0, 8, 1), - (2, 'Super-Man delivery' , 1, 0, 8, 1), - (3, 'Teleportation device' , 1, 0, 8, 1), - (4, 'Entanglement' , 1, 0, 8, 1), - (5, 'Quantum break device' , 1, 0, 8, 1), - (6, 'Walking' , 1, 0, 8, 1), - (7, 'Silla247' , 1, 0, 8, 1), - (8, 'Silla247Expensive' , 1, 0, 8, 1), - (9, 'Abono' , 1, 0, 8, 1); + (1, 'inhouse pickup' , 1, 0, 8, 1, NULL), + (2, 'Super-Man delivery' , 1, 0, 8, 1, NULL), + (3, 'Teleportation device' , 1, 0, 8, 1, NULL), + (4, 'Entanglement' , 1, 0, 8, 1, NULL), + (5, 'Quantum break device' , 1, 0, 8, 1, NULL), + (6, 'Walking' , 1, 0, 8, 1, NULL), + (7, 'Silla247' , 1, 0, 8, 1, NULL), + (8, 'Silla247Expensive' , 1, 0, 8, 1, NULL), + (9, 'Abono' , 1, 0, 8, 1, 'refund'); UPDATE `vn`.`agencyMode` SET `id` = 1 WHERE `name` = 'inhouse pickup'; UPDATE `vn`.`agencyMode` SET `id` = 2 WHERE `name` = 'Super-Man delivery'; @@ -272,7 +272,8 @@ INSERT INTO `vn`.`observationType`(`id`,`description`) VALUES (1,'observation one'), (2,'observation two'), - (3,'observation three'); + (3,'observation three'), + (4,'comercial'); INSERT INTO `vn`.`addressObservation`(`id`,`addressFk`,`observationTypeFk`,`description`) VALUES