From f7100f11ee2454e247bf770e27d6cd7958df969a Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Thu, 16 Jul 2020 07:43:07 +0200 Subject: [PATCH 1/9] first step add right menu in ticket components --- db/dump/fixtures.sql | 54 ++++++++++--------- .../back/methods/ticket/freightPorts.js | 26 +++++++++ modules/ticket/back/models/ticket.js | 1 + .../front/basic-data/step-two/index.html | 42 ++++++++------- .../front/basic-data/step-two/locale/es.yml | 5 +- modules/ticket/front/component/index.html | 23 ++++++-- modules/ticket/front/component/index.js | 30 ++++++++++- modules/ticket/front/component/locale/es.yml | 1 + modules/ticket/front/component/style.scss | 3 ++ 9 files changed, 136 insertions(+), 49 deletions(-) create mode 100644 modules/ticket/back/methods/ticket/freightPorts.js create mode 100644 modules/ticket/front/component/locale/es.yml diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index e146ff893..8cf0a6fb0 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -523,32 +523,32 @@ INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agen (6, NULL, 57, CURDATE(), 5, 7, 'sixth route', 1.7, 60, CURDATE(), CURDATE(), 3), (7, NULL, 57, CURDATE(), 6, 8, 'seventh route', 0, 70, CURDATE(), CURDATE(), 5); -INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `landed`, `clientFk`,`nickname`, `addressFk`, `refFk`, `isDeleted`, `zoneFk`, `created`) +INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `landed`, `clientFk`,`nickname`, `addressFk`, `refFk`, `isDeleted`, `zoneFk`,`zonePrice`, `zoneBonus`, `created`) VALUES - (1 , 3, 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 101, 'Bat cave', 121, 'T1111111', 0, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), - (2 , 1, 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T1111111', 0, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), - (3 , 1, 7, 1, 6, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -2 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T2222222', 0, 3, DATE_ADD(CURDATE(), INTERVAL -2 MONTH)), - (4 , 3, 2, 1, 2, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -3 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T3333333', 0, 9, DATE_ADD(CURDATE(), INTERVAL -3 MONTH)), - (5 , 3, 3, 3, 3, DATE_ADD(CURDATE(), INTERVAL -4 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -4 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T4444444', 0, 10, DATE_ADD(CURDATE(), INTERVAL -4 MONTH)), - (6 , 1, 3, 3, 3, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 101, 'Mountain Drive Gotham', 1, 'A1111111', 0, 10, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), - (7 , NULL, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 101, 'Mountain Drive Gotham', 1, NULL, 0, 3, CURDATE()), - (8 , NULL, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 101, 'Bat cave', 121, NULL, 0, 3, CURDATE()), - (9 , NULL, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 104, 'Stark tower', 124, NULL, 0, 3, CURDATE()), - (10, 1, 1, 5, 1, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 102, 'Ingram Street', 2, NULL, 0, 1, CURDATE()), - (11, 1, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 102, 'NY roofs', 122, NULL, 0, 3, CURDATE()), - (12, 1, 1, 1, 1, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 103, 'Phone Box', 123, NULL, 0, 1, CURDATE()), - (13, 1, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 103, 'Phone Box', 123, NULL, 0, 3, CURDATE()), - (14, 1, 2, 1, NULL, CURDATE(), CURDATE(), 104, 'Malibu Point', 4, NULL, 0, 9, CURDATE()), - (15, 1, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 105, 'Plastic Cell', 125, NULL, 0, 3, CURDATE()), - (16, 1, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 106, 'Many Places', 126, NULL, 0, 3, CURDATE()), - (17, 1, 7, 2, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 106, 'Many Places', 126, NULL, 0, 3, CURDATE()), - (18, 1, 4, 4, 4, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 108, 'Cerebro', 128, NULL, 0, 12, CURDATE()), - (19, 1, 5, 5, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 109, 'Somewhere in Thailand', 129, NULL, 1, 13, CURDATE()), - (20, 1, 5, 5, 3, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 109, 'Somewhere in Thailand', 129, NULL, 0, 13, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), - (21, NULL, 5, 5, 5, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 109, 'Somewhere in Holland', 102, NULL, 0, 13, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), - (22, NULL, 5, 5, 5, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 109, 'Somewhere in Japan', 103, NULL, 0, 13, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), - (23, NULL, 8, 1, 7, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 101, 'address 21', 121, NULL, 0, 5, CURDATE()), - (24 ,NULL, 8, 1, 7, CURDATE(), CURDATE(), 101, 'Bruce Wayne', 1, NULL, 0, 5, CURDATE()); + (1 , 3, 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 101, 'Bat cave', 121, 'T1111111', 0, 1, 5, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), + (2 , 1, 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T1111111', 0, 1, 5, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), + (3 , 1, 7, 1, 6, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -2 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T2222222', 0, 3, 5, 1, DATE_ADD(CURDATE(), INTERVAL -2 MONTH)), + (4 , 3, 2, 1, 2, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -3 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T3333333', 0, 9, 5, 1, DATE_ADD(CURDATE(), INTERVAL -3 MONTH)), + (5 , 3, 3, 3, 3, DATE_ADD(CURDATE(), INTERVAL -4 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -4 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T4444444', 0, 10, 5, 1, DATE_ADD(CURDATE(), INTERVAL -4 MONTH)), + (6 , 1, 3, 3, 3, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 101, 'Mountain Drive Gotham', 1, 'A1111111', 0, 10, 5, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), + (7 , NULL, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 101, 'Mountain Drive Gotham', 1, NULL, 0, 3, 5, 1, CURDATE()), + (8 , NULL, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 101, 'Bat cave', 121, NULL, 0, 3, 5, 1, CURDATE()), + (9 , NULL, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 104, 'Stark tower', 124, NULL, 0, 3, 5, 1, CURDATE()), + (10, 1, 1, 5, 1, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 102, 'Ingram Street', 2, NULL, 0, 1, 5, 1, CURDATE()), + (11, 1, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 102, 'NY roofs', 122, NULL, 0, 3, 5, 1, CURDATE()), + (12, 1, 1, 1, 1, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 103, 'Phone Box', 123, NULL, 0, 1, 5, 1, CURDATE()), + (13, 1, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 103, 'Phone Box', 123, NULL, 0, 3, 5, 1, CURDATE()), + (14, 1, 2, 1, NULL, CURDATE(), CURDATE(), 104, 'Malibu Point', 4, NULL, 0, 9, 5, 1, CURDATE()), + (15, 1, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 105, 'Plastic Cell', 125, NULL, 0, 3, 5, 1, CURDATE()), + (16, 1, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 106, 'Many Places', 126, NULL, 0, 3, 5, 1, CURDATE()), + (17, 1, 7, 2, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 106, 'Many Places', 126, NULL, 0, 3, 5, 1, CURDATE()), + (18, 1, 4, 4, 4, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 108, 'Cerebro', 128, NULL, 0, 12, 5, 1, CURDATE()), + (19, 1, 5, 5, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 109, 'Somewhere in Thailand', 129, NULL, 1, 13, 5, 1, CURDATE()), + (20, 1, 5, 5, 3, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 109, 'Somewhere in Thailand', 129, NULL, 0, 13, 5, 1, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), + (21, NULL, 5, 5, 5, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 109, 'Somewhere in Holland', 102, NULL, 0, 13, 5, 1, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), + (22, NULL, 5, 5, 5, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 109, 'Somewhere in Japan', 103, NULL, 0, 13, 5, 1, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), + (23, NULL, 8, 1, 7, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 101, 'address 21', 121, NULL, 0, 5, 5, 1, CURDATE()), + (24 ,NULL, 8, 1, 7, CURDATE(), CURDATE(), 101, 'Bruce Wayne', 1, NULL, 0, 5, 5, 1, CURDATE()); INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `description`) VALUES @@ -749,6 +749,10 @@ INSERT INTO `vn`.`expedition`(`id`, `agencyModeFk`, `ticketFk`, `isBox`, `create (9, 3, 6, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 1, 1, 1, 18), (10, 7, 7, 71, CURDATE(), 1, 1, 1, 18); +INSERT INTO `vn`.`expeditionBoxVol`(`boxFk`, `m3`, `ratio`) + VALUES + (71,0.141,1); + INSERT INTO `vn`.`packaging`(`id`, `volume`, `width`, `height`, `depth`, `isPackageReturnable`, `created`, `itemFk`, `price`) VALUES (1, 0.00, 10, 10, 0, 1, CURDATE(), 6, 1.50), diff --git a/modules/ticket/back/methods/ticket/freightPorts.js b/modules/ticket/back/methods/ticket/freightPorts.js new file mode 100644 index 000000000..52204c096 --- /dev/null +++ b/modules/ticket/back/methods/ticket/freightPorts.js @@ -0,0 +1,26 @@ +module.exports = Self => { + Self.remoteMethod('freightPorts', { + description: 'Returns the freight cost of a ticket', + accessType: 'READ', + accepts: { + arg: 'id', + type: 'number', + required: true, + description: 'ticket id', + http: {source: 'path'} + }, + returns: { + type: 'Number', + root: true + }, + http: { + path: `/:id/freightPorts`, + verb: 'GET' + } + }); + + Self.freightPorts = async ticketFk => { + const [freightCost] = await Self.rawSql(`SELECT vn.ticket_getFreightCost(?) total`, [ticketFk]); + return freightCost.total; + }; +}; diff --git a/modules/ticket/back/models/ticket.js b/modules/ticket/back/models/ticket.js index a2891430a..3afc6301c 100644 --- a/modules/ticket/back/models/ticket.js +++ b/modules/ticket/back/models/ticket.js @@ -30,6 +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); Self.observe('before save', async function(ctx) { if (ctx.isNewInstance) return; diff --git a/modules/ticket/front/basic-data/step-two/index.html b/modules/ticket/front/basic-data/step-two/index.html index 39e7753fc..0e22100c2 100644 --- a/modules/ticket/front/basic-data/step-two/index.html +++ b/modules/ticket/front/basic-data/step-two/index.html @@ -3,21 +3,6 @@ data="ticketUpdateActions" auto-load="true"> - -
- Charge difference to -
-
- - -
-
@@ -51,10 +36,31 @@ - {{$ctrl.totalPrice | currency: 'EUR': 2}} - {{$ctrl.totalNewPrice | currency: 'EUR': 2}} - {{$ctrl.totalPriceDifference | currency: 'EUR': 2}} + +
+
+
Total
+
Price {{$ctrl.totalPrice | currency: 'EUR': 2}}
+
New price {{$ctrl.totalNewPrice | currency: 'EUR': 2}}
+
Difference {{$ctrl.totalPriceDifference | currency: 'EUR': 2}}
+
+ +
+
Charge difference to
+
+ + +
+
+
+
+
+ + diff --git a/modules/ticket/front/basic-data/step-two/locale/es.yml b/modules/ticket/front/basic-data/step-two/locale/es.yml index 49dd7fd80..a2a07991b 100644 --- a/modules/ticket/front/basic-data/step-two/locale/es.yml +++ b/modules/ticket/front/basic-data/step-two/locale/es.yml @@ -2,4 +2,7 @@ Price (PPU): Precio (Ud.) New (PPU): Nuevo (Ud.) Difference: Diferencia Charge difference to: Cargar diferencia a -The ticket has been unrouted: El ticket ha sido desenrutado \ No newline at end of file +The ticket has been unrouted: El ticket ha sido desenrutado +Price: Precio +New price: Nuevo precio +Price difference: Diferencia de precio \ No newline at end of file diff --git a/modules/ticket/front/component/index.html b/modules/ticket/front/component/index.html index 20ee592c1..6706df1af 100644 --- a/modules/ticket/front/component/index.html +++ b/modules/ticket/front/component/index.html @@ -7,9 +7,6 @@ auto-load="true"> - - Base to commission {{$ctrl.base() | currency: 'EUR':3}} - @@ -64,6 +61,26 @@
+ +
+
+
Total
+
Base to commission {{$ctrl.base() | currency: 'EUR':3}}
+
Total {{$ctrl.getTotal() | currency: 'EUR': 2}}
+
+
+
Total
+
Price {{$ctrl.totalPrice | currency: 'EUR': 2}}
+
New price {{$ctrl.totalNewPrice | currency: 'EUR': 2}}
+
Difference {{$ctrl.totalPriceDifference | currency: 'EUR': 2}}
+
+
+
Theorical ports
+
Price {{$ctrl.theoricalPorts | currency: 'EUR': 2}}
+
+
+
+ diff --git a/modules/ticket/front/component/index.js b/modules/ticket/front/component/index.js index 3efd7d56d..b40efcd12 100644 --- a/modules/ticket/front/component/index.js +++ b/modules/ticket/front/component/index.js @@ -29,11 +29,20 @@ class Controller extends Section { }] }; } + get ticket() { + return this._ticket; + } + + set ticket(value) { + this._ticket = value; + + if (!value) return; + this.getTheoricalPorts(); + } base() { let sales = this.$.model.data; let sum = 0; - if (!sales) return; for (let sale of sales) { @@ -42,9 +51,26 @@ class Controller extends Section { sum += sale.quantity * saleComponent.value; } } - return sum; } + + getTotal() { + let sales = this.$.model.data; + let total = 0; + if (!sales) return; + for (let sale of sales) { + for (let saleComponent of sale.components) + total += sale.quantity * saleComponent.value; + } + return total; + } + + getTheoricalPorts() { + this.$http.get(`Tickets/${this.ticket.id}/freightPorts`) + .then(res => this.theoricalPorts = res.data); + + console.log('this.THasdasdasdeoricalPorts', this.theoricalPorts); + } } ngModule.component('vnTicketComponents', { diff --git a/modules/ticket/front/component/locale/es.yml b/modules/ticket/front/component/locale/es.yml new file mode 100644 index 000000000..a230b61b3 --- /dev/null +++ b/modules/ticket/front/component/locale/es.yml @@ -0,0 +1 @@ +Theorical ports: Portes teóricos \ No newline at end of file diff --git a/modules/ticket/front/component/style.scss b/modules/ticket/front/component/style.scss index d1a8ac9c4..5ca1e5e2b 100644 --- a/modules/ticket/front/component/style.scss +++ b/modules/ticket/front/component/style.scss @@ -24,4 +24,7 @@ vn-ticket-components { } } } + .totalBox { + max-width: none; + } } From b972353bb4954a5b85b8eb297910528be8e7198d Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Tue, 21 Jul 2020 11:11:09 +0200 Subject: [PATCH 2/9] create method getComponentSum --- .../back/methods/ticket/getComponentsSum.js | 32 +++++++++++++++++++ modules/ticket/back/models/ticket.js | 1 + modules/ticket/front/component/index.html | 4 +-- modules/ticket/front/component/index.js | 6 +++- 4 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 modules/ticket/back/methods/ticket/getComponentsSum.js diff --git a/modules/ticket/back/methods/ticket/getComponentsSum.js b/modules/ticket/back/methods/ticket/getComponentsSum.js new file mode 100644 index 000000000..d254b3af3 --- /dev/null +++ b/modules/ticket/back/methods/ticket/getComponentsSum.js @@ -0,0 +1,32 @@ +module.exports = Self => { + Self.remoteMethod('getComponentsSum', { + description: 'Returns the list of component and their sum from a ticket', + accessType: 'READ', + accepts: { + arg: 'id', + type: 'number', + required: true, + description: 'ticket id', + http: {source: 'path'} + }, + returns: { + type: 'Number', + root: true + }, + http: { + path: `/:id/getComponentsSum`, + verb: 'GET' + } + }); + + Self.getComponentsSum = async id => { + const models = Self.app.models; + let sales = await models.Sale.find({where: {ticketFk: id}}); + let salesComponents; + for (let sale of sales) { + salesComponents = await models.SaleComponent.find({saleFk: sale.id}); + console.log('salesComponents', salesComponents); + } + return true; + }; +}; diff --git a/modules/ticket/back/models/ticket.js b/modules/ticket/back/models/ticket.js index 3afc6301c..d6ef50fb3 100644 --- a/modules/ticket/back/models/ticket.js +++ b/modules/ticket/back/models/ticket.js @@ -31,6 +31,7 @@ module.exports = Self => { require('../methods/ticket/sendSms')(Self); require('../methods/ticket/isLocked')(Self); require('../methods/ticket/freightPorts')(Self); + require('../methods/ticket/getComponentsSum')(Self); Self.observe('before save', async function(ctx) { if (ctx.isNewInstance) return; diff --git a/modules/ticket/front/component/index.html b/modules/ticket/front/component/index.html index 6706df1af..4cfbd3ce6 100644 --- a/modules/ticket/front/component/index.html +++ b/modules/ticket/front/component/index.html @@ -62,7 +62,7 @@ -
+
Total
Base to commission {{$ctrl.base() | currency: 'EUR':3}}
@@ -78,7 +78,7 @@
Theorical ports
Price {{$ctrl.theoricalPorts | currency: 'EUR': 2}}
-
+
this.theoricalPorts = res.data); + } - console.log('this.THasdasdasdeoricalPorts', this.theoricalPorts); + getComponentsSum() { + this.$http.get(`Tickets/${this.ticket.id}/getComponentsSum`) + .then(res => this.componentsList = res.data); } } From 92e14d529288dbf014c16038046ae8533f101f94 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Tue, 8 Sep 2020 07:17:16 +0200 Subject: [PATCH 3/9] update getComponentSum --- front/core/components/radio/style.scss | 5 ++++ front/core/components/toggle/index.html | 4 +-- .../back/methods/ticket/getComponentsSum.js | 30 +++++++++++++++---- modules/ticket/front/component/index.html | 16 +++++----- modules/ticket/front/component/locale/es.yml | 3 +- 5 files changed, 43 insertions(+), 15 deletions(-) diff --git a/front/core/components/radio/style.scss b/front/core/components/radio/style.scss index 2ee037e65..dfb3ac955 100644 --- a/front/core/components/radio/style.scss +++ b/front/core/components/radio/style.scss @@ -1,6 +1,7 @@ @import "variables"; .vn-radio { + & > .btn { border-radius: 50%; @@ -25,4 +26,8 @@ &.disabled.checked > .btn > .mark { background-color: $color-font-secondary; } + > div { + text-overflow: ellipsis; + overflow: hidden; + } } diff --git a/front/core/components/toggle/index.html b/front/core/components/toggle/index.html index 3ec11242e..b41f837a2 100644 --- a/front/core/components/toggle/index.html +++ b/front/core/components/toggle/index.html @@ -2,6 +2,6 @@
- +
{{::$ctrl.label}} - \ No newline at end of file +
\ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/getComponentsSum.js b/modules/ticket/back/methods/ticket/getComponentsSum.js index d254b3af3..7646123ab 100644 --- a/modules/ticket/back/methods/ticket/getComponentsSum.js +++ b/modules/ticket/back/methods/ticket/getComponentsSum.js @@ -18,15 +18,35 @@ module.exports = Self => { verb: 'GET' } }); - Self.getComponentsSum = async id => { const models = Self.app.models; let sales = await models.Sale.find({where: {ticketFk: id}}); - let salesComponents; + let components = await models.Component.find(); + let salesComponents = []; + let componentsSum = []; + for (let sale of sales) { - salesComponents = await models.SaleComponent.find({saleFk: sale.id}); - console.log('salesComponents', salesComponents); + let myComponents = await models.SaleComponent.find({where: {saleFk: sale.id}}); + salesComponents = salesComponents.concat(myComponents); } - return true; + + salesComponents.reduce((acumulator, currentValue) => { + if (!acumulator[currentValue.componentFk]) { + let defaultValue = 0; + let tarjetComponent = components.find(component => component.id === currentValue.componentFk); + + acumulator[currentValue.componentFk] = { + componentFk: currentValue.componentFk, + value: defaultValue, + name: tarjetComponent.name + }; + componentsSum.push(acumulator[currentValue.componentFk]); + } + + acumulator[currentValue.componentFk].value += currentValue.value; + + return acumulator; + }); + return componentsSum; }; }; diff --git a/modules/ticket/front/component/index.html b/modules/ticket/front/component/index.html index 4cfbd3ce6..03d5122a1 100644 --- a/modules/ticket/front/component/index.html +++ b/modules/ticket/front/component/index.html @@ -65,17 +65,19 @@
Total
-
Base to commission {{$ctrl.base() | currency: 'EUR':3}}
-
Total {{$ctrl.getTotal() | currency: 'EUR': 2}}
+
Base to commission {{$ctrl.base() | currency: 'EUR':2}}
+
Total without VAT {{$ctrl.getTotal() | currency: 'EUR': 3}}
-
Total
-
Price {{$ctrl.totalPrice | currency: 'EUR': 2}}
-
New price {{$ctrl.totalNewPrice | currency: 'EUR': 2}}
-
Difference {{$ctrl.totalPriceDifference | currency: 'EUR': 2}}
+
Components
+
+
+ {{component.name}} {{component.value | currency: 'EUR': 3}} +
+
-
Theorical ports
+
Theorical port
Price {{$ctrl.theoricalPorts | currency: 'EUR': 2}}
diff --git a/modules/ticket/front/component/locale/es.yml b/modules/ticket/front/component/locale/es.yml index a230b61b3..4d196ffe7 100644 --- a/modules/ticket/front/component/locale/es.yml +++ b/modules/ticket/front/component/locale/es.yml @@ -1 +1,2 @@ -Theorical ports: Portes teóricos \ No newline at end of file +Theorical port: Porte teorico +Total without VAT: Total sin IVA \ No newline at end of file From d79cffb2c373b6d3abfd3f1233afcc448a2a61c9 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Tue, 8 Sep 2020 08:13:54 +0200 Subject: [PATCH 4/9] back test for getComponentsSum --- .../back/methods/ticket/getComponentsSum.js | 45 ++++++++++--------- .../ticket/specs/getComponentsSum.spec.js | 18 ++++++++ 2 files changed, 41 insertions(+), 22 deletions(-) create mode 100644 modules/ticket/back/methods/ticket/specs/getComponentsSum.spec.js diff --git a/modules/ticket/back/methods/ticket/getComponentsSum.js b/modules/ticket/back/methods/ticket/getComponentsSum.js index 7646123ab..febf4eab1 100644 --- a/modules/ticket/back/methods/ticket/getComponentsSum.js +++ b/modules/ticket/back/methods/ticket/getComponentsSum.js @@ -20,33 +20,34 @@ module.exports = Self => { }); Self.getComponentsSum = async id => { const models = Self.app.models; - let sales = await models.Sale.find({where: {ticketFk: id}}); - let components = await models.Component.find(); let salesComponents = []; let componentsSum = []; - - for (let sale of sales) { - let myComponents = await models.SaleComponent.find({where: {saleFk: sale.id}}); - salesComponents = salesComponents.concat(myComponents); - } - - salesComponents.reduce((acumulator, currentValue) => { - if (!acumulator[currentValue.componentFk]) { - let defaultValue = 0; - let tarjetComponent = components.find(component => component.id === currentValue.componentFk); - - acumulator[currentValue.componentFk] = { - componentFk: currentValue.componentFk, - value: defaultValue, - name: tarjetComponent.name - }; - componentsSum.push(acumulator[currentValue.componentFk]); + let sales = await models.Sale.find({where: {ticketFk: id}}); + let components = await models.Component.find(); + if (sales.length > 0) { + for (let sale of sales) { + let myComponents = await models.SaleComponent.find({where: {saleFk: sale.id}}); + salesComponents = salesComponents.concat(myComponents); } - acumulator[currentValue.componentFk].value += currentValue.value; + salesComponents.reduce((acumulator, currentValue) => { + if (!acumulator[currentValue.componentFk]) { + let defaultValue = 0; + let tarjetComponent = components.find(component => component.id === currentValue.componentFk); - return acumulator; - }); + acumulator[currentValue.componentFk] = { + componentFk: currentValue.componentFk, + value: defaultValue, + name: tarjetComponent.name + }; + componentsSum.push(acumulator[currentValue.componentFk]); + } + + acumulator[currentValue.componentFk].value += currentValue.value; + + return acumulator; + }); + } return componentsSum; }; }; diff --git a/modules/ticket/back/methods/ticket/specs/getComponentsSum.spec.js b/modules/ticket/back/methods/ticket/specs/getComponentsSum.spec.js new file mode 100644 index 000000000..876e9f615 --- /dev/null +++ b/modules/ticket/back/methods/ticket/specs/getComponentsSum.spec.js @@ -0,0 +1,18 @@ +const app = require('vn-loopback/server/server'); + +fdescribe('ticket getComponentsSum()', () => { + it('should get the list of component of their sales of a given ticket', async() => { + let ticketId = 7; + let mana = await app.models.Ticket.getComponentsSum(ticketId); + + expect(mana.length).toBeGreaterThan(0); + expect(mana[0].componentFk).toBe(22); + }); + + it('should return 0 if the given ticket does not have sales', async() => { + let ticketWithoutSales = 21; + let mana = await app.models.Ticket.getComponentsSum(ticketWithoutSales); + + expect(mana.length).toEqual(0); + }); +}); From f99fb69d48ab52359a95ffe4f21e2975c21d073e Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Wed, 9 Sep 2020 08:20:27 +0200 Subject: [PATCH 5/9] front and back test --- e2e/paths/11-zone/02_descriptor.spec.js | 2 +- .../methods/ticket/specs/freightPorts.spec.js | 17 ++++ .../ticket/specs/getComponentsSum.spec.js | 14 +-- modules/ticket/front/component/index.spec.js | 92 ++++++++++++++----- 4 files changed, 94 insertions(+), 31 deletions(-) create mode 100644 modules/ticket/back/methods/ticket/specs/freightPorts.spec.js diff --git a/e2e/paths/11-zone/02_descriptor.spec.js b/e2e/paths/11-zone/02_descriptor.spec.js index 1de84d601..df904ecdb 100644 --- a/e2e/paths/11-zone/02_descriptor.spec.js +++ b/e2e/paths/11-zone/02_descriptor.spec.js @@ -1,7 +1,7 @@ import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; -describe('Zone descriptor path', () => { +fdescribe('Zone descriptor path', () => { let browser; let page; diff --git a/modules/ticket/back/methods/ticket/specs/freightPorts.spec.js b/modules/ticket/back/methods/ticket/specs/freightPorts.spec.js new file mode 100644 index 000000000..bbed2316f --- /dev/null +++ b/modules/ticket/back/methods/ticket/specs/freightPorts.spec.js @@ -0,0 +1,17 @@ +const app = require('vn-loopback/server/server'); + +describe('ticket freightPorts()', () => { + it('should return the freight cost of a given ticket', async() => { + let ticketId = 7; + let freightCost = await app.models.Ticket.freightPorts(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); + + 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 876e9f615..81c735835 100644 --- a/modules/ticket/back/methods/ticket/specs/getComponentsSum.spec.js +++ b/modules/ticket/back/methods/ticket/specs/getComponentsSum.spec.js @@ -1,18 +1,18 @@ const app = require('vn-loopback/server/server'); -fdescribe('ticket getComponentsSum()', () => { - it('should get the list of component of their sales of a given ticket', async() => { +describe('ticket getComponentsSum()', () => { + it('should get the list of component for the ticket sales', async() => { let ticketId = 7; - let mana = await app.models.Ticket.getComponentsSum(ticketId); + let components = await app.models.Ticket.getComponentsSum(ticketId); - expect(mana.length).toBeGreaterThan(0); - expect(mana[0].componentFk).toBe(22); + expect(components.length).toBeGreaterThan(0); + expect(components[0].componentFk).toBe(22); }); it('should return 0 if the given ticket does not have sales', async() => { let ticketWithoutSales = 21; - let mana = await app.models.Ticket.getComponentsSum(ticketWithoutSales); + let components = await app.models.Ticket.getComponentsSum(ticketWithoutSales); - expect(mana.length).toEqual(0); + expect(components.length).toEqual(0); }); }); diff --git a/modules/ticket/front/component/index.spec.js b/modules/ticket/front/component/index.spec.js index 1cffcdb52..ead6eb2f2 100644 --- a/modules/ticket/front/component/index.spec.js +++ b/modules/ticket/front/component/index.spec.js @@ -4,76 +4,72 @@ import crudModel from 'core/mocks/crud-model'; describe('ticket', () => { describe('Component vnTicketComponents', () => { let controller; + let $httpBackend; beforeEach(ngModule('ticket')); - beforeEach(inject(($componentController, $rootScope, $state) => { + beforeEach(inject(($componentController, $rootScope, $state, _$httpBackend_) => { $state.params.id = '1'; let $scope = $rootScope.$new(); + $httpBackend = _$httpBackend_; $scope.model = crudModel; $scope.model.data = [{ + quantity: 1, components: [ { + value: 5, component: { - name: 'valor de compra', componentType: { isBase: 1 } - }, - value: 5 + } }, { + value: 5, component: { - name: 'reparto', componentType: { isBase: 0 } - }, - value: 5 + } }, { + value: 5, component: { - name: 'recobro', componentType: { isBase: 0 } - }, - value: 5 + } } - ], - quantity: 1 + ] }, { + quantity: 5, components: [ { + value: 1, component: { - name: 'valor de compra', componentType: { isBase: 1 } - }, - value: 1 + } }, { + value: 1, component: { - name: 'reparto', componentType: { isBase: 0 } - }, - value: 1 + } }, { + value: 1, component: { - name: 'recobro', componentType: { isBase: 0 } - }, - value: 1 + } }, - ], - quantity: 5 + ] }]; const $element = angular.element(''); controller = $componentController('vnTicketComponents', {$element, $scope}); @@ -86,5 +82,55 @@ describe('ticket', () => { expect(result).toEqual(10); }); }); + + describe('ticket setter', () => { + it('should set the ticket data and then call getTheoricalPorts() and getComponentsSum()', () => { + jest.spyOn(controller, 'getTheoricalPorts'); + jest.spyOn(controller, 'getComponentsSum'); + controller._ticket = undefined; + controller.ticket = { + id: 7 + }; + + expect(controller.ticket).toBeDefined(); + expect(controller.getTheoricalPorts).toHaveBeenCalledWith(); + expect(controller.getComponentsSum).toHaveBeenCalledWith(); + }); + }); + + describe('getTotal()', () => { + it('should return the total sum of a ticket', () => { + let result = controller.getTotal(); + + expect(result).toEqual(30); + }); + }); + + describe('getTheoricalPorts()', () => { + 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.flush(); + + expect(controller.theoricalPorts).toBe('My freight port'); + }); + }); + + describe('getComponentsSum()', () => { + it('should make a request to get the component list', () => { + controller._ticket = { + id: 7 + }; + + $httpBackend.expect('GET', `Tickets/${controller._ticket.id}/getComponentsSum`).respond('My component list'); + controller.getComponentsSum(); + $httpBackend.flush(); + + expect(controller.componentsList).toBe('My component list'); + }); + }); }); }); From b3b2261b4acbf2af3005a25edcd75274ad06d4f1 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Wed, 9 Sep 2020 08:29:52 +0200 Subject: [PATCH 6/9] delete fdescribe --- e2e/paths/11-zone/02_descriptor.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/paths/11-zone/02_descriptor.spec.js b/e2e/paths/11-zone/02_descriptor.spec.js index df904ecdb..1de84d601 100644 --- a/e2e/paths/11-zone/02_descriptor.spec.js +++ b/e2e/paths/11-zone/02_descriptor.spec.js @@ -1,7 +1,7 @@ import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; -fdescribe('Zone descriptor path', () => { +describe('Zone descriptor path', () => { let browser; let page; From ed926c39a1906f2813220b9711c74006bf929615 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Wed, 9 Sep 2020 11:27:00 +0200 Subject: [PATCH 7/9] fix e2e --- db/dump/fixtures.sql | 2 +- e2e/helpers/selectors.js | 4 ++-- e2e/paths/05-ticket/08_components.spec.js | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index eea1036c1..254f9a74c 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -560,7 +560,7 @@ INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeF (16, 1, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 106, 'Many Places', 126, NULL, 0, 3, 5, 1, CURDATE()), (17, 1, 7, 2, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 106, 'Many Places', 126, NULL, 0, 3, 5, 1, CURDATE()), (18, 1, 4, 4, 4, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 108, 'Cerebro', 128, NULL, 0, 12, 5, 1, CURDATE()), - (19, 1, 5, 5, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 109, 'Somewhere in Thailand', 129, NULL, 1, 13, 5, 1, CURDATE()), + (19, 1, 5, 5, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 109, 'Somewhere in Thailand', 129, NULL, 1, NULL, 5, 1, CURDATE()), (20, 1, 5, 5, 3, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 109, 'Somewhere in Thailand', 129, NULL, 0, 13, 5, 1, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), (21, NULL, 5, 5, 5, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 109, 'Somewhere in Holland', 102, NULL, 0, 13, 5, 1, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), (22, NULL, 5, 5, 5, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 109, 'Somewhere in Japan', 103, NULL, 0, 13, 5, 1, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index c1e13d889..421d6de16 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -521,11 +521,11 @@ export default { zone: 'vn-autocomplete[ng-model="$ctrl.zoneId"]', nextStepButton: 'vn-step-control .buttons > section:last-child vn-button', finalizeButton: 'vn-step-control .buttons > section:last-child button[type=submit]', - stepTwoTotalPriceDif: 'vn-ticket-basic-data-step-two vn-tfoot > vn-tr > :nth-child(6)', + stepTwoTotalPriceDif: 'vn-ticket-basic-data-step-two > vn-side-menu div:nth-child(4)', chargesReason: 'vn-ticket-basic-data-step-two div:nth-child(3) > vn-radio', }, ticketComponents: { - base: 'vn-ticket-components [name="base-sum"]' + base: 'vn-ticket-components > vn-side-menu div:nth-child(1) > div:nth-child(2)' }, ticketRequests: { addRequestButton: 'vn-ticket-request-index > a > vn-float-button > button', diff --git a/e2e/paths/05-ticket/08_components.spec.js b/e2e/paths/05-ticket/08_components.spec.js index ae631d5dd..ab2aa85b2 100644 --- a/e2e/paths/05-ticket/08_components.spec.js +++ b/e2e/paths/05-ticket/08_components.spec.js @@ -24,7 +24,6 @@ describe('Ticket List components path', () => { await page.waitPropertyLength(selectors.ticketComponents.base, 'innerText', minLength); const base = await page.waitToGetProperty(selectors.ticketComponents.base, 'innerText'); - expect(base).toContain('Base'); expect(base.length).toBeGreaterThan(minLength); }); From d4b6d7cd96d11012430475c2c6b03f4edaa11690 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Wed, 9 Sep 2020 15:49:59 +0200 Subject: [PATCH 8/9] 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 + } } From 12ceedd80c9b2fb3fce0a617c677ec0ad500213a Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Thu, 10 Sep 2020 10:46:56 +0200 Subject: [PATCH 9/9] corrected some typos --- modules/ticket/front/component/index.html | 2 +- modules/ticket/front/component/index.spec.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/ticket/front/component/index.html b/modules/ticket/front/component/index.html index 79cc1c7bc..fb8af3219 100644 --- a/modules/ticket/front/component/index.html +++ b/modules/ticket/front/component/index.html @@ -76,7 +76,7 @@
-
Theorical port
+
Theorical cost
Price {{$ctrl.theoricalCost | currency: 'EUR': 2}}
diff --git a/modules/ticket/front/component/index.spec.js b/modules/ticket/front/component/index.spec.js index 9930ece4c..053248c2c 100644 --- a/modules/ticket/front/component/index.spec.js +++ b/modules/ticket/front/component/index.spec.js @@ -107,15 +107,15 @@ describe('ticket', () => { }); describe('getTheoricalCost()', () => { - it('should make a request to get the theorical port of a ticket', () => { + it('should make a request to get the theorical cost of a ticket', () => { controller._ticket = { id: 7 }; - $httpBackend.expect('GET', `Tickets/${controller._ticket.id}/freightCost`).respond('My freight port'); + $httpBackend.expect('GET', `Tickets/${controller._ticket.id}/freightCost`).respond('My freight cost'); controller.getTheoricalCost(); $httpBackend.flush(); - expect(controller.theoricalCost).toBe('My freight port'); + expect(controller.theoricalCost).toBe('My freight cost'); }); });