diff --git a/front/salix/components/user-configuration-popover/index.js b/front/salix/components/user-configuration-popover/index.js index f16b1134c..ddade39bb 100644 --- a/front/salix/components/user-configuration-popover/index.js +++ b/front/salix/components/user-configuration-popover/index.js @@ -43,7 +43,7 @@ class Controller { set warehouseFk(value) { this.warehouse = value; - if (!window.localStorage.defaultWarehouseFk) + if (value && !window.localStorage.localWarehouseFk) window.localStorage.defaultWarehouseFk = value; this.setUserConfig('warehouseFk', value); } @@ -54,7 +54,7 @@ class Controller { set companyFk(value) { this.company = value; - if (!window.localStorage.defaultCompanyFk) + if (value && !window.localStorage.localCompanyFk) window.localStorage.defaultCompanyFk = value; this.setUserConfig('companyFk', value); } @@ -80,13 +80,13 @@ class Controller { .then(res => { if (res.data && res.data.warehouseFk) { this.warehouse = res.data.warehouseFk; - if (!window.localStorage.defaultWarehouseFk || window.localStorage.defaultWarehouseFk === 'null') + if (res.data.warehouseFk && !window.localStorage.localWarehouseFk) window.localStorage.defaultWarehouseFk = res.data.warehouseFk; } if (res.data && res.data.companyFk) { this.company = res.data.companyFk; - if (!window.localStorage.defaultCompanyFk || window.localStorage.defaultCompanyFk === 'null') + if (res.data.companyFk && !window.localStorage.localCompanyFk) window.localStorage.defaultCompanyFk = res.data.companyFk; } }); diff --git a/modules/agency/back/methods/agency/getLanded.js b/modules/agency/back/methods/agency/getLanded.js new file mode 100644 index 000000000..978f639a6 --- /dev/null +++ b/modules/agency/back/methods/agency/getLanded.js @@ -0,0 +1,28 @@ +module.exports = Self => { + Self.remoteMethod('getLanded', { + description: 'Returns the first shipped and landed possible for params', + accessType: 'READ', + accepts: [{ + arg: 'params', + type: 'object', + required: true, + description: 'shipped, addressFk, agencyModeFk, warehouseFk' + }], + returns: { + type: 'object', + root: true + }, + http: { + path: `/getLanded`, + verb: 'get' + } + }); + + Self.getLanded = async params => { + let query = `CALL vn.agencyHourGetLanded(?, ?, ?, ?); + SELECT * FROM tmp.agencyHourGetLanded`; + let result = await Self.rawSql(query, [params.shipped, params.addressFk || null, params.agencyModeFk, params.warehouseFk]); + + return result[1][0].landed; + }; +}; diff --git a/modules/agency/back/methods/agency/getShipped.js b/modules/agency/back/methods/agency/getShipped.js new file mode 100644 index 000000000..04fa62a89 --- /dev/null +++ b/modules/agency/back/methods/agency/getShipped.js @@ -0,0 +1,28 @@ +module.exports = Self => { + Self.remoteMethod('getShipped', { + description: 'Returns the first shipped possible for params', + accessType: 'READ', + accepts: [{ + arg: 'params', + type: 'object', + required: true, + description: 'landed, addressFk, agencyModeFk' + }], + returns: { + type: 'object', + root: true + }, + http: { + path: `/getShipped`, + verb: 'get' + } + }); + + Self.getShipped = async params => { + let query = `CALL vn.agencyHourGetShipped(?, ?, ?); + SELECT * FROM tmp.agencyHourGetShipped`; + let result = await Self.rawSql(query, [params.landed, params.addressFk, params.agencyModeFk]); + + return result[1][0].shipped; + }; +}; diff --git a/modules/agency/back/models/agency.js b/modules/agency/back/models/agency.js index 1478b0b8c..e115a41f4 100644 --- a/modules/agency/back/models/agency.js +++ b/modules/agency/back/models/agency.js @@ -2,4 +2,6 @@ module.exports = Self => { require('../methods/agency/landsThatDay')(Self); require('../methods/agency/getFirstShipped')(Self); require('../methods/agency/getAgenciesWithWarehouse')(Self); + require('../methods/agency/getLanded')(Self); + require('../methods/agency/getShipped')(Self); }; diff --git a/modules/client/front/risk/create/index.js b/modules/client/front/risk/create/index.js index c040b9348..a828d7264 100644 --- a/modules/client/front/risk/create/index.js +++ b/modules/client/front/risk/create/index.js @@ -23,9 +23,8 @@ class Controller { if (this.$stateParams.amountPaid) this.receipt.amountPaid = this.$stateParams.amountPaid; - if (this.$stateParams.companyFk) { + if (this.$stateParams.companyFk) this.receipt.companyFk = this.$stateParams.companyFk; - } } $onInit() { diff --git a/modules/ticket/back/methods/ticket/new.js b/modules/ticket/back/methods/ticket/new.js index c41362804..c92f09832 100644 --- a/modules/ticket/back/methods/ticket/new.js +++ b/modules/ticket/back/methods/ticket/new.js @@ -57,6 +57,24 @@ module.exports = Self => { throw new UserError(`You can't create a ticket for a client that has a debt`); } + if (!params.shipped && params.landed) { + params.shipped = await Self.app.models.Agency.getShipped({ + landed: params.landed, + addressFk: address.id, + agencyModeFk: params.agencyModeFk + }); + } + + if (params.shipped && !params.landed) { + params.landed = await Self.app.models.Agency.getLanded({ + shipped: params.shipped, + addressFk: address.id, + agencyModeFk: params.agencyModeFk, + warehouseFk: params.warehouseFk + }); + } + + if (!params.userId && ctx.req && ctx.req.accessToken.userId) params.userId = ctx.req.accessToken.userId; diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index 3add4446b..5b27bd0dc 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); describe('ticket filter()', () => { - it('should call the filter method', async () => { + it('should call the filter method', async() => { let ctx = {req: {accessToken: {userId: 9}}}; let filter = {order: 'shipped DESC'}; diff --git a/modules/ticket/front/create/card.html b/modules/ticket/front/create/card.html index 7007de94f..4d11ea8e5 100644 --- a/modules/ticket/front/create/card.html +++ b/modules/ticket/front/create/card.html @@ -27,7 +27,7 @@ ini-options="{enableTime: false}">