diff --git a/back/methods/user-config/getUserConfig.js b/back/methods/user-config/getUserConfig.js
index 665d00966..e5ade8ada 100644
--- a/back/methods/user-config/getUserConfig.js
+++ b/back/methods/user-config/getUserConfig.js
@@ -13,9 +13,8 @@ module.exports = function(Self) {
});
Self.getUserConfig = async ctx => {
- let token = ctx.req.accessToken;
- let currentUserId = token && token.userId;
-
- return await Self.findOne({userFk: currentUserId});
+ return await Self.app.models.UserConfig.findOne({
+ where: {userFk: ctx.req.accessToken.userId}
+ });
};
};
diff --git a/back/methods/user-config/setUserConfig.js b/back/methods/user-config/setUserConfig.js
index bd258b832..098ba9866 100644
--- a/back/methods/user-config/setUserConfig.js
+++ b/back/methods/user-config/setUserConfig.js
@@ -24,5 +24,5 @@ module.exports = function(Self) {
params.userFk = currentUserId;
return await Self.app.models.UserConfig.upsertWithWhere({userFk: currentUserId}, params);
- }
+ };
};
diff --git a/front/salix/components/main-menu/main-menu.html b/front/salix/components/main-menu/main-menu.html
index cebe1e0ce..d03ca33c0 100644
--- a/front/salix/components/main-menu/main-menu.html
+++ b/front/salix/components/main-menu/main-menu.html
@@ -50,7 +50,5 @@
ng-click="$ctrl.onLogoutClick()">
-
-
-
-
\ No newline at end of file
+
+
\ No newline at end of file
diff --git a/front/salix/components/main-menu/main-menu.js b/front/salix/components/main-menu/main-menu.js
index bd6b53678..880d959d6 100644
--- a/front/salix/components/main-menu/main-menu.js
+++ b/front/salix/components/main-menu/main-menu.js
@@ -37,8 +37,7 @@ export default class MainMenu {
}
openUserConfiguration(event) {
- this.$.popover.parent = event.target;
- this.$.popover.show();
+ this.$.popover.show(event);
}
onLogoutClick() {
diff --git a/front/salix/components/user-configuration-popover/index.html b/front/salix/components/user-configuration-popover/index.html
index 898700609..1c771c713 100644
--- a/front/salix/components/user-configuration-popover/index.html
+++ b/front/salix/components/user-configuration-popover/index.html
@@ -1,79 +1,85 @@
-
-
-
+
+
+
+
+
+
\ No newline at end of file
diff --git a/front/salix/components/user-configuration-popover/index.js b/front/salix/components/user-configuration-popover/index.js
index a6bda1ad1..ddade39bb 100644
--- a/front/salix/components/user-configuration-popover/index.js
+++ b/front/salix/components/user-configuration-popover/index.js
@@ -43,7 +43,9 @@ class Controller {
set warehouseFk(value) {
this.warehouse = value;
- this.setUserConfig('warehouseFk');
+ if (value && !window.localStorage.localWarehouseFk)
+ window.localStorage.defaultWarehouseFk = value;
+ this.setUserConfig('warehouseFk', value);
}
get warehouseFk() {
@@ -52,7 +54,9 @@ class Controller {
set companyFk(value) {
this.company = value;
- this.setUserConfig('companyFk');
+ if (value && !window.localStorage.localCompanyFk)
+ window.localStorage.defaultCompanyFk = value;
+ this.setUserConfig('companyFk', value);
}
get companyFk() {
@@ -63,31 +67,39 @@ class Controller {
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
}
- getUserConfig() {
- this.$http.get('/api/UserConfigs/getUserConfig')
- .then(res => {
- if (res.data && res.data.warehouseFk) {
- this.warehouse = res.data.warehouseFk;
- if (!localStorage.getItem('localWarehouseFk'))
- localStorage.setItem('defaultWarehouseFk', res.data.warehouseFk);
- }
-
- if (res.data && res.data.companyFk) {
- this.company = res.data.companyFk;
- if (!localStorage.getItem('localCompanyFk'))
- localStorage.setItem('defaultCompanyFk', res.data.companyFk);
- }
- });
+ show(event) {
+ this.$scope.banks.refresh();
+ this.$scope.warehouses.refresh();
+ this.$scope.companies.refresh();
+ this.$scope.popover.parent = event.target;
+ this.$scope.popover.show();
}
- setUserConfig(property) {
+ getUserConfig() {
+ this.$http.get('/api/UserConfigs/getUserConfig')
+ .then(res => {
+ if (res.data && res.data.warehouseFk) {
+ this.warehouse = res.data.warehouseFk;
+ 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 (res.data.companyFk && !window.localStorage.localCompanyFk)
+ window.localStorage.defaultCompanyFk = res.data.companyFk;
+ }
+ });
+ }
+
+ setUserConfig(property, value) {
let params = {};
- params[property] = this[property];
+ params[property] = value;
this.$http.post('/api/UserConfigs/setUserConfig', params)
- .then(() => {
- this.showOk();
- });
+ .then(() => {
+ this.showOk();
+ });
}
$onInit() {
diff --git a/front/salix/components/user-configuration-popover/index.spec.js b/front/salix/components/user-configuration-popover/index.spec.js
index d6c61de29..829ff674a 100644
--- a/front/salix/components/user-configuration-popover/index.spec.js
+++ b/front/salix/components/user-configuration-popover/index.spec.js
@@ -50,7 +50,7 @@ describe('Salix', () => {
controller.warehouseFk = 4;
expect(controller.warehouse).toBe(4);
- expect(controller.setUserConfig).toHaveBeenCalledWith('warehouseFk');
+ expect(controller.setUserConfig).toHaveBeenCalledWith('warehouseFk', 4);
});
});
@@ -60,7 +60,7 @@ describe('Salix', () => {
controller.companyFk = 4;
expect(controller.company).toBe(4);
- expect(controller.setUserConfig).toHaveBeenCalledWith('companyFk');
+ expect(controller.setUserConfig).toHaveBeenCalledWith('companyFk', 4);
});
});
@@ -83,8 +83,8 @@ describe('Salix', () => {
$httpBackend.when('GET', `/api/UserConfigs/getUserConfig`).respond({companyFk: 2});
$httpBackend.expect('GET', `/api/UserConfigs/getUserConfig`);
$httpBackend.when('POST', `/api/UserConfigs/setUserConfig`, {companyFk: 1}).respond(200);
- $httpBackend.expect('POST', `/api/UserConfigs/setUserConfig`, {companyFk: 1});
- controller.setUserConfig('companyFk');
+ $httpBackend.expect('POST', `/api/UserConfigs/setUserConfig`);
+ controller.setUserConfig('companyFk', 1);
$httpBackend.flush();
expect(controller.showOk).toHaveBeenCalledWith();
diff --git a/front/salix/components/user-configuration-popover/locale/es.yml b/front/salix/components/user-configuration-popover/locale/es.yml
new file mode 100644
index 000000000..3961f69ad
--- /dev/null
+++ b/front/salix/components/user-configuration-popover/locale/es.yml
@@ -0,0 +1,5 @@
+Local warehouse: Almacén local
+Local bank: Banco local
+Local company: Compañia local
+User warehouse: Almacén del usuario
+User company: Compañia del usuario
\ No newline at end of file
diff --git a/front/salix/components/user-configuration-popover/style.scss b/front/salix/components/user-configuration-popover/style.scss
index d370cc279..acd0495e6 100644
--- a/front/salix/components/user-configuration-popover/style.scss
+++ b/front/salix/components/user-configuration-popover/style.scss
@@ -1,12 +1,13 @@
@import 'colors';
vn-user-configuration-popover {
- color: $main-font-color;
- & > vn-vertical {
- min-width: 250px;
+ vn-popover {
+ color: $main-font-color;
+ vn-vertical {
+ min-width: 250px;
+ }
+ .body {
+ padding: 16px 16px 6px 16px;
+ }
}
- .body {
- padding: 16px 16px 6px 16px;
- }
-
}
\ No newline at end of file
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/client/front/risk/index/index.html b/modules/client/front/risk/index/index.html
index 273299f7c..d5740cc71 100644
--- a/modules/client/front/risk/index/index.html
+++ b/modules/client/front/risk/index/index.html
@@ -3,12 +3,13 @@
url="/client/api/receipts/filter"
params="$ctrl.params"
limit="20"
- data="$ctrl.risks">
+ data="$ctrl.risks"
+ auto-load="true">
diff --git a/modules/client/front/risk/index/index.js b/modules/client/front/risk/index/index.js
index 5744c6fb1..14c1be3b7 100644
--- a/modules/client/front/risk/index/index.js
+++ b/modules/client/front/risk/index/index.js
@@ -18,6 +18,7 @@ class Controller {
},
where: {
clientFk: $stateParams.id,
+ companyFk: this.companyFk
},
};
this.params = {
@@ -29,7 +30,9 @@ class Controller {
}
setOrder(value) {
this.params.params.companyFk = value;
+ this.filter.where.companyFk = value;
this.$.model.refresh();
+ this.$.riskModel.refresh();
}
set risks(value) {
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}">