From 7b40fe29421e536faa7effc3456f8671490f8792 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 2 Sep 2019 14:36:54 +0200 Subject: [PATCH] ticket.basicData Update zone on changes + fixes #1668 --- .../back/methods/ticket/priceDifference.js | 12 +-- .../front/basic-data/step-one/index.html | 3 +- .../ticket/front/basic-data/step-one/index.js | 87 ++++++++++++++----- .../ticket/front/basic-data/step-two/index.js | 7 +- 4 files changed, 78 insertions(+), 31 deletions(-) diff --git a/modules/ticket/back/methods/ticket/priceDifference.js b/modules/ticket/back/methods/ticket/priceDifference.js index 552c2b991..122d20e50 100644 --- a/modules/ticket/back/methods/ticket/priceDifference.js +++ b/modules/ticket/back/methods/ticket/priceDifference.js @@ -94,14 +94,16 @@ module.exports = Self => { salesObj.items.forEach(sale => { const difComponent = map.get(sale.id); - if (difComponent) + if (difComponent) { sale.component = difComponent; + salesObj.totalNewPrice += sale.component.newPrice; + salesObj.totalDifference += sale.component.difference; + salesObj.totalUnitPrice = Math.round(salesObj.totalUnitPrice * 100) / 100; + salesObj.totalNewPrice = Math.round(salesObj.totalNewPrice * 100) / 100; + } + salesObj.totalUnitPrice += sale.price; - salesObj.totalNewPrice += sale.component.newPrice; - salesObj.totalDifference += sale.component.difference; - salesObj.totalUnitPrice = Math.round(salesObj.totalUnitPrice * 100) / 100; - salesObj.totalNewPrice = Math.round(salesObj.totalNewPrice * 100) / 100; salesObj.totalDifference = Math.round(salesObj.totalDifference * 100) / 100; }); diff --git a/modules/ticket/front/basic-data/step-one/index.html b/modules/ticket/front/basic-data/step-one/index.html index d3f2807b9..4a636f49a 100644 --- a/modules/ticket/front/basic-data/step-one/index.html +++ b/modules/ticket/front/basic-data/step-one/index.html @@ -36,8 +36,7 @@ label="Warehouse" show-field="name" value-field="id" - field="$ctrl.ticket.warehouseFk" - initial-data="$ctrl.ticket.warehouseFk"> + field="$ctrl.warehouseId"> diff --git a/modules/ticket/front/basic-data/step-one/index.js b/modules/ticket/front/basic-data/step-one/index.js index be8e380e5..afe4d4c75 100644 --- a/modules/ticket/front/basic-data/step-one/index.js +++ b/modules/ticket/front/basic-data/step-one/index.js @@ -39,11 +39,21 @@ class Controller { this.onChangeClient(value); } - set shipped(value) { - this.ticket.shipped = value; - this.onChangeShipped(value); + get warehouseId() { + if (this.ticket) + return this.ticket.warehouseFk; + + return null; } + set warehouseId(id) { + if (id != this.ticket.warehouseFk) { + this.ticket.warehouseFk = id; + this.onChangeWarehouse(id); + } + } + + get shipped() { if (this.ticket) return this.ticket.shipped; @@ -51,6 +61,11 @@ class Controller { return null; } + set shipped(value) { + this.ticket.shipped = value; + this.onChangeShipped(value); + } + get landed() { if (this.ticket) return this.ticket.landed; @@ -120,23 +135,6 @@ class Controller { }); } - /* - * Returns a landing date - */ - getLanded(params) { - let query = `/api/Agencies/getLanded`; - return this.$http.get(query, {params}); - } - - /* - * Returns a shipment date - */ - getShipped(params) { - let query = `/api/Agencies/getShipped`; - return this.$http.get(query, {params}); - } - - onChangeShipped(shipped) { let params = { shipped: shipped, @@ -144,6 +142,8 @@ class Controller { agencyModeFk: this.ticket.agencyModeFk, warehouseFk: this.ticket.warehouseFk }; + this.ticket.zoneFk = null; + let query = `/api/Agencies/getLanded`; this.$http.get(query, {params}).then(res => { if (res.data && res.data.landed) { @@ -164,6 +164,8 @@ class Controller { agencyModeFk: this.ticket.agencyModeFk, warehouseFk: this.ticket.warehouseFk }; + this.ticket.zoneFk = null; + let query = `/api/Agencies/getShipped`; this.$http.get(query, {params}).then(res => { if (res.data) { @@ -183,8 +185,10 @@ class Controller { onChangeZone(zoneId) { const query = `/api/Zones/${zoneId}`; this.$http.get(query).then(res => { - if (res.data) + if (res.data) { this.ticket.agencyModeFk = res.data.agencyModeFk; + this.ticket.warehouseFk = res.data.warehouseFk; + } }); } @@ -212,6 +216,31 @@ class Controller { }); } + /* + * Gets a zone from an agency + */ + onChangeWarehouse(warehouseId) { + let params = { + landed: this.ticket.landed, + addressFk: this.ticket.addressFk, + agencyModeFk: this.ticket.agencyModeFk, + warehouseFk: warehouseId + }; + + this.ticket.zoneFk = null; + let query = `/api/Agencies/getShipped`; + this.$http.get(query, {params}).then(res => { + if (res.data) + this.ticket.zoneFk = res.data.id; + + if (!res.data) { + this.vnApp.showMessage( + this.$translate.instant('No delivery zone available for this parameters') + ); + } + }); + } + async onStepChange() { if (this.isFormInvalid()) { return this.vnApp.showError( @@ -240,6 +269,22 @@ class Controller { }); } + /* + * Returns a landing date + */ + getLanded(params) { + let query = `/api/Agencies/getLanded`; + return this.$http.get(query, {params}); + } + + /* + * Returns a shipment date + */ + getShipped(params) { + let query = `/api/Agencies/getShipped`; + return this.$http.get(query, {params}); + } + isFormInvalid() { return !this.ticket.clientFk || !this.ticket.addressFk || !this.ticket.agencyModeFk || !this.ticket.companyFk || !this.ticket.shipped || !this.ticket.landed diff --git a/modules/ticket/front/basic-data/step-two/index.js b/modules/ticket/front/basic-data/step-two/index.js index 1d18f6ba0..1446ac171 100644 --- a/modules/ticket/front/basic-data/step-two/index.js +++ b/modules/ticket/front/basic-data/step-two/index.js @@ -28,8 +28,8 @@ class Controller { getTotalNewPrice() { let totalNewPrice = 0; this.ticket.sale.items.forEach(item => { - let itemTotalNewPrice = item.quantity * item.component.newPrice; - totalNewPrice += itemTotalNewPrice; + if (item.component) + totalNewPrice += item.quantity * item.component.newPrice; }); this.totalNewPrice = totalNewPrice; } @@ -37,7 +37,8 @@ class Controller { getTotalDifferenceOfPrice() { let totalPriceDifference = 0; this.ticket.sale.items.forEach(item => { - totalPriceDifference += item.component.difference; + if (item.component) + totalPriceDifference += item.component.difference; }); this.totalPriceDifference = totalPriceDifference; }