From d4b6d7cd96d11012430475c2c6b03f4edaa11690 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Wed, 9 Sep 2020 15:49:59 +0200 Subject: [PATCH] cr changes --- .../{freightPorts.js => freightCost.js} | 6 +-- .../back/methods/ticket/getComponentsSum.js | 2 +- ...eightPorts.spec.js => freightCost.spec.js} | 6 +-- .../ticket/specs/getComponentsSum.spec.js | 12 +++--- modules/ticket/back/models/ticket.js | 2 +- .../front/basic-data/step-two/index.html | 10 ++--- .../ticket/front/basic-data/step-two/index.js | 1 + .../front/basic-data/step-two/style.scss | 9 +++++ modules/ticket/front/component/index.html | 39 +++++++++---------- modules/ticket/front/component/index.js | 11 +++--- modules/ticket/front/component/index.spec.js | 14 +++---- modules/ticket/front/component/locale/es.yml | 2 +- modules/ticket/front/component/style.scss | 12 ++++++ 13 files changed, 74 insertions(+), 52 deletions(-) rename modules/ticket/back/methods/ticket/{freightPorts.js => freightCost.js} (82%) rename modules/ticket/back/methods/ticket/specs/{freightPorts.spec.js => freightCost.spec.js} (64%) create mode 100644 modules/ticket/front/basic-data/step-two/style.scss diff --git a/modules/ticket/back/methods/ticket/freightPorts.js b/modules/ticket/back/methods/ticket/freightCost.js similarity index 82% rename from modules/ticket/back/methods/ticket/freightPorts.js rename to modules/ticket/back/methods/ticket/freightCost.js index 52204c096..008121f8f 100644 --- a/modules/ticket/back/methods/ticket/freightPorts.js +++ b/modules/ticket/back/methods/ticket/freightCost.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.remoteMethod('freightPorts', { + Self.remoteMethod('freightCost', { description: 'Returns the freight cost of a ticket', accessType: 'READ', accepts: { @@ -14,12 +14,12 @@ module.exports = Self => { root: true }, http: { - path: `/:id/freightPorts`, + path: `/:id/freightCost`, verb: 'GET' } }); - Self.freightPorts = async ticketFk => { + Self.freightCost = async ticketFk => { const [freightCost] = await Self.rawSql(`SELECT vn.ticket_getFreightCost(?) total`, [ticketFk]); return freightCost.total; }; diff --git a/modules/ticket/back/methods/ticket/getComponentsSum.js b/modules/ticket/back/methods/ticket/getComponentsSum.js index febf4eab1..c5333288e 100644 --- a/modules/ticket/back/methods/ticket/getComponentsSum.js +++ b/modules/ticket/back/methods/ticket/getComponentsSum.js @@ -1,6 +1,6 @@ module.exports = Self => { Self.remoteMethod('getComponentsSum', { - description: 'Returns the list of component and their sum from a ticket', + description: 'Returns a list of component and their sum from a ticket', accessType: 'READ', accepts: { arg: 'id', diff --git a/modules/ticket/back/methods/ticket/specs/freightPorts.spec.js b/modules/ticket/back/methods/ticket/specs/freightCost.spec.js similarity index 64% rename from modules/ticket/back/methods/ticket/specs/freightPorts.spec.js rename to modules/ticket/back/methods/ticket/specs/freightCost.spec.js index bbed2316f..cb8f5a562 100644 --- a/modules/ticket/back/methods/ticket/specs/freightPorts.spec.js +++ b/modules/ticket/back/methods/ticket/specs/freightCost.spec.js @@ -1,16 +1,16 @@ const app = require('vn-loopback/server/server'); -describe('ticket freightPorts()', () => { +describe('ticket freightCost()', () => { it('should return the freight cost of a given ticket', async() => { let ticketId = 7; - let freightCost = await app.models.Ticket.freightPorts(ticketId); + let freightCost = await app.models.Ticket.freightCost(ticketId); expect(freightCost).toBe(4); }); it('should return null if the ticket does not exist', async() => { let ticketId = 99; - let freightCost = await app.models.Ticket.freightPorts(ticketId); + let freightCost = await app.models.Ticket.freightCost(ticketId); expect(freightCost).toBeNull(); }); diff --git a/modules/ticket/back/methods/ticket/specs/getComponentsSum.spec.js b/modules/ticket/back/methods/ticket/specs/getComponentsSum.spec.js index 81c735835..4be8de3f0 100644 --- a/modules/ticket/back/methods/ticket/specs/getComponentsSum.spec.js +++ b/modules/ticket/back/methods/ticket/specs/getComponentsSum.spec.js @@ -2,16 +2,18 @@ const app = require('vn-loopback/server/server'); describe('ticket getComponentsSum()', () => { it('should get the list of component for the ticket sales', async() => { - let ticketId = 7; - let components = await app.models.Ticket.getComponentsSum(ticketId); + const ticketId = 7; + const components = await app.models.Ticket.getComponentsSum(ticketId); + const length = components.length; + const anyComponent = components[Math.floor(Math.random() * Math.floor(length))]; expect(components.length).toBeGreaterThan(0); - expect(components[0].componentFk).toBe(22); + expect(anyComponent.componentFk).toBeDefined(); }); it('should return 0 if the given ticket does not have sales', async() => { - let ticketWithoutSales = 21; - let components = await app.models.Ticket.getComponentsSum(ticketWithoutSales); + const ticketWithoutSales = 21; + const components = await app.models.Ticket.getComponentsSum(ticketWithoutSales); expect(components.length).toEqual(0); }); diff --git a/modules/ticket/back/models/ticket.js b/modules/ticket/back/models/ticket.js index d6ef50fb3..1150b7367 100644 --- a/modules/ticket/back/models/ticket.js +++ b/modules/ticket/back/models/ticket.js @@ -30,7 +30,7 @@ module.exports = Self => { require('../methods/ticket/deleteStowaway')(Self); require('../methods/ticket/sendSms')(Self); require('../methods/ticket/isLocked')(Self); - require('../methods/ticket/freightPorts')(Self); + require('../methods/ticket/freightCost')(Self); require('../methods/ticket/getComponentsSum')(Self); Self.observe('before save', async function(ctx) { diff --git a/modules/ticket/front/basic-data/step-two/index.html b/modules/ticket/front/basic-data/step-two/index.html index 0e22100c2..fe0667c49 100644 --- a/modules/ticket/front/basic-data/step-two/index.html +++ b/modules/ticket/front/basic-data/step-two/index.html @@ -8,7 +8,7 @@ Item - Description + Description Quantity Price (PPU) New (PPU) @@ -42,15 +42,15 @@
-
-
Total
+
+
Total
Price {{$ctrl.totalPrice | currency: 'EUR': 2}}
New price {{$ctrl.totalNewPrice | currency: 'EUR': 2}}
Difference {{$ctrl.totalPriceDifference | currency: 'EUR': 2}}
-
-
Charge difference to
+
+
Charge difference to
- + - -
-
Total
-
Base to commission {{$ctrl.base() | currency: 'EUR':2}}
-
Total without VAT {{$ctrl.getTotal() | currency: 'EUR': 3}}
-
-
-
Components
-
-
- {{component.name}} {{component.value | currency: 'EUR': 3}} -
-
-
-
-
Theorical port
-
Price {{$ctrl.theoricalPorts | currency: 'EUR': 2}}
-
- +
+
Total
+
Base to commission {{$ctrl.base() | currency: 'EUR':2}}
+
Total without VAT {{$ctrl.getTotal() | currency: 'EUR': 3}}
+
+
+
Components
+
+
+ {{component.name}} {{component.value | currency: 'EUR': 3}} +
+
+
+
+
Theorical port
+
Price {{$ctrl.theoricalCost | currency: 'EUR': 2}}
+
- diff --git a/modules/ticket/front/component/index.js b/modules/ticket/front/component/index.js index fd1ea4220..7557bfba6 100644 --- a/modules/ticket/front/component/index.js +++ b/modules/ticket/front/component/index.js @@ -37,7 +37,8 @@ class Controller extends Section { this._ticket = value; if (!value) return; - this.getTheoricalPorts(); + + this.getTheoricalCost(); this.getComponentsSum(); } @@ -56,7 +57,7 @@ class Controller extends Section { } getTotal() { - let sales = this.$.model.data; + const sales = this.$.model.data; let total = 0; if (!sales) return; for (let sale of sales) { @@ -66,9 +67,9 @@ class Controller extends Section { return total; } - getTheoricalPorts() { - this.$http.get(`Tickets/${this.ticket.id}/freightPorts`) - .then(res => this.theoricalPorts = res.data); + getTheoricalCost() { + this.$http.get(`Tickets/${this.ticket.id}/freightCost`) + .then(res => this.theoricalCost = res.data); } getComponentsSum() { diff --git a/modules/ticket/front/component/index.spec.js b/modules/ticket/front/component/index.spec.js index ead6eb2f2..9930ece4c 100644 --- a/modules/ticket/front/component/index.spec.js +++ b/modules/ticket/front/component/index.spec.js @@ -84,8 +84,8 @@ describe('ticket', () => { }); describe('ticket setter', () => { - it('should set the ticket data and then call getTheoricalPorts() and getComponentsSum()', () => { - jest.spyOn(controller, 'getTheoricalPorts'); + it('should set the ticket data and then call getTheoricalCost() and getComponentsSum()', () => { + jest.spyOn(controller, 'getTheoricalCost'); jest.spyOn(controller, 'getComponentsSum'); controller._ticket = undefined; controller.ticket = { @@ -93,7 +93,7 @@ describe('ticket', () => { }; expect(controller.ticket).toBeDefined(); - expect(controller.getTheoricalPorts).toHaveBeenCalledWith(); + expect(controller.getTheoricalCost).toHaveBeenCalledWith(); expect(controller.getComponentsSum).toHaveBeenCalledWith(); }); }); @@ -106,16 +106,16 @@ describe('ticket', () => { }); }); - describe('getTheoricalPorts()', () => { + describe('getTheoricalCost()', () => { it('should make a request to get the theorical port of a ticket', () => { controller._ticket = { id: 7 }; - $httpBackend.expect('GET', `Tickets/${controller._ticket.id}/freightPorts`).respond('My freight port'); - controller.getTheoricalPorts(); + $httpBackend.expect('GET', `Tickets/${controller._ticket.id}/freightCost`).respond('My freight port'); + controller.getTheoricalCost(); $httpBackend.flush(); - expect(controller.theoricalPorts).toBe('My freight port'); + expect(controller.theoricalCost).toBe('My freight port'); }); }); diff --git a/modules/ticket/front/component/locale/es.yml b/modules/ticket/front/component/locale/es.yml index 4d196ffe7..57dcf64e0 100644 --- a/modules/ticket/front/component/locale/es.yml +++ b/modules/ticket/front/component/locale/es.yml @@ -1,2 +1,2 @@ -Theorical port: Porte teorico +Theorical cost: Porte teorico Total without VAT: Total sin IVA \ No newline at end of file diff --git a/modules/ticket/front/component/style.scss b/modules/ticket/front/component/style.scss index 5ca1e5e2b..aa4318a9e 100644 --- a/modules/ticket/front/component/style.scss +++ b/modules/ticket/front/component/style.scss @@ -27,4 +27,16 @@ vn-ticket-components { .totalBox { max-width: none; } + + .align-left { + text-align: left + } + + .align-center { + text-align: center + } + + .initial { + height: initial + } }