diff --git a/modules/ticket/front/basic-data/step-one/index.js b/modules/ticket/front/basic-data/step-one/index.js index e7eb305831..e1e74ae3f8 100644 --- a/modules/ticket/front/basic-data/step-one/index.js +++ b/modules/ticket/front/basic-data/step-one/index.js @@ -56,8 +56,16 @@ class Controller extends Component { set warehouseId(value) { if (value != this.ticket.warehouseFk) { this.ticket.warehouseFk = value; - this.ticket.agencyModeFk = null; - this.ticket.zoneFk = null; + + this.getShipped({ + landed: this.ticket.landed, + addressFk: this.ticket.addressFk, + agencyModeFk: this.ticket.agencyModeFk, + warehouseFk: value + }).then(() => { + if (this.zoneId == null) + this.ticket.agencyModeFk = null; + }); } } @@ -177,8 +185,8 @@ class Controller extends Component { ); } - let query = `tickets/${this.ticket.id}/priceDifference`; - let params = { + const query = `tickets/${this.ticket.id}/priceDifference`; + const params = { landed: this.ticket.landed, addressId: this.ticket.addressFk, agencyModeId: this.ticket.agencyModeFk, @@ -202,9 +210,13 @@ class Controller extends Component { * Returns a landing date */ getLanded(params) { + const validParams = this.shipped && this.addressId + && this.agencyModeId && this.warehouseId; + if (!validParams) return this.$q.resolve(); + this.ticket.zoneFk = null; const query = `Agencies/getLanded`; - this.$http.get(query, {params}).then(res => { + return this.$http.get(query, {params}).then(res => { if (res.data) { this.ticket.zoneFk = res.data.zoneFk; this.ticket.landed = res.data.landed; @@ -221,9 +233,13 @@ class Controller extends Component { * Returns a shipment date */ getShipped(params) { + const validParams = this.landed && this.addressId + && this.agencyModeId && this.warehouseId; + if (!validParams) return this.$q.resolve(); + this.ticket.zoneFk = null; const query = `Agencies/getShipped`; - this.$http.get(query, {params}).then(res => { + return this.$http.get(query, {params}).then(res => { if (res.data) { this.ticket.zoneFk = res.data.zoneFk; this.ticket.landed = params.landed; diff --git a/modules/zone/back/methods/agency/getLanded.js b/modules/zone/back/methods/agency/getLanded.js index 27ac88327a..4505c68ddf 100644 --- a/modules/zone/back/methods/agency/getLanded.js +++ b/modules/zone/back/methods/agency/getLanded.js @@ -37,9 +37,12 @@ module.exports = Self => { Self.getLanded = async(ctx, shipped, addressFk, agencyModeFk, warehouseFk) => { const userId = ctx.req.accessToken.userId; const models = Self.app.models; - const isProductionBoss = await models.Account.hasRole(userId, 'productionBoss'); + const roles = await models.Account.getRoles(userId); + const canSeeExpired = roles.filter(role => + role == 'productionBoss' || role == 'administrative' + ); let showExpired = false; - if (isProductionBoss) showExpired = true; + if (canSeeExpired.length) showExpired = true; let stmts = []; stmts.push(new ParameterizedSQL( diff --git a/modules/zone/back/methods/zone/includingExpired.js b/modules/zone/back/methods/zone/includingExpired.js index 6428d5b887..a27d044668 100644 --- a/modules/zone/back/methods/zone/includingExpired.js +++ b/modules/zone/back/methods/zone/includingExpired.js @@ -32,9 +32,12 @@ module.exports = Self => { && where.agencyModeFk && where.warehouseFk; if (filterByAvailability) { - const isProductionBoss = await models.Account.hasRole(userId, 'productionBoss'); + const roles = await models.Account.getRoles(userId); + const canSeeExpired = roles.filter(role => + role == 'productionBoss' || role == 'administrative' + ); let showExpired = false; - if (isProductionBoss) showExpired = true; + if (canSeeExpired.length) showExpired = true; stmt = new ParameterizedSQL(`CALL vn.zone_getLanded(?, ?, ?, ?, ?)`, [ where.shipped,