This commit is contained in:
Juan Ferrer 2019-01-25 12:04:46 +01:00
commit e76d0aaf71
20 changed files with 229 additions and 121 deletions

View File

@ -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}
});
};
};

View File

@ -24,5 +24,5 @@ module.exports = function(Self) {
params.userFk = currentUserId;
return await Self.app.models.UserConfig.upsertWithWhere({userFk: currentUserId}, params);
}
};
};

View File

@ -50,7 +50,5 @@
ng-click="$ctrl.onLogoutClick()">
</vn-icon>
</div>
<vn-popover vn-id="popover">
<vn-user-configuration-popover>
</vn-user-configuration-popover>
</vn-popover>
<vn-user-configuration-popover vn-id="popover">
</vn-user-configuration-popover>

View File

@ -37,8 +37,7 @@ export default class MainMenu {
}
openUserConfiguration(event) {
this.$.popover.parent = event.target;
this.$.popover.show();
this.$.popover.show(event);
}
onLogoutClick() {

View File

@ -1,79 +1,85 @@
<vn-crud-model
url="/api/Banks"
data="banks"
vn-id="banks"
data="banksData"
order="bank">
</vn-crud-model>
<vn-crud-model
url="/api/Warehouses"
data="warehouses"
vn-id="warehouses"
data="warehousesData"
order="name">
</vn-crud-model>
<vn-crud-model
url="/api/Companies"
data="companies"
vn-id="companies"
data="companiesData"
order="code">
</vn-crud-model>
<vn-vertical class="body">
<form name="form" ng-submit="$ctrl.onSubmit()">
<vn-horizontal>
<vn-autocomplete
vn-one
label="Local warehouse"
id="localWarehouse"
field="$ctrl.localWarehouseFk"
data="warehouses"
select-fields="['id','name']"
show-field="name"
value-field="id">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
label="Local bank"
id="localBank"
field="$ctrl.localBankFk"
data="banks"
select-fields="['id','bank']"
show-field="bank"
value-field="id">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
label="Local company"
id="localCompany"
field="$ctrl.localCompanyFk"
data="companies"
select-fields="['id','code']"
show-field="code"
value-field="id">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
label="User warehouse"
id="userWarehouse"
field="$ctrl.warehouseFk"
data="warehouses"
select-fields="['id', 'name']"
show-field="name"
value-field="id">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
label="User company"
id="userCompany"
field="$ctrl.companyFk"
data="companies"
select-fields="['id', 'code']"
show-field="code"
value-field="id">
</vn-autocomplete>
</vn-horizontal>
</form>
</vn-vertical>
<vn-popover vn-id="popover">
<vn-vertical class="body">
<form name="form" ng-submit="$ctrl.onSubmit()">
<vn-horizontal>
<vn-autocomplete
vn-one
label="Local warehouse"
id="localWarehouse"
field="$ctrl.localWarehouseFk"
data="warehousesData"
select-fields="['id','name']"
show-field="name"
value-field="id">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
label="Local bank"
id="localBank"
field="$ctrl.localBankFk"
data="banksData"
select-fields="['id','bank']"
show-field="bank"
value-field="id">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
label="Local company"
id="localCompany"
field="$ctrl.localCompanyFk"
data="companiesData"
select-fields="['id','code']"
show-field="code"
value-field="id">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
label="User warehouse"
id="userWarehouse"
field="$ctrl.warehouseFk"
data="warehousesData"
select-fields="['id', 'name']"
show-field="name"
value-field="id">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
label="User company"
id="userCompany"
field="$ctrl.companyFk"
data="companiesData"
select-fields="['id', 'code']"
show-field="code"
value-field="id">
</vn-autocomplete>
</vn-horizontal>
</form>
</vn-vertical>
</vn-popover>

View File

@ -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() {

View File

@ -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();

View File

@ -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

View File

@ -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;
}
}

View File

@ -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;
};
};

View File

@ -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;
};
};

View File

@ -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);
};

View File

@ -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() {

View File

@ -3,12 +3,13 @@
url="/client/api/receipts/filter"
params="$ctrl.params"
limit="20"
data="$ctrl.risks">
data="$ctrl.risks"
auto-load="true">
</vn-crud-model>
<vn-crud-model
vn-id="riskModel"
url="/client/api/ClientRisks"
filter="::$ctrl.filter"
filter="$ctrl.filter"
data="riskTotal"
auto-load="true">
</vn-crud-model>

View File

@ -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) {

View File

@ -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;

View File

@ -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'};

View File

@ -27,7 +27,7 @@
ini-options="{enableTime: false}">
</vn-date-picker>
<vn-autocomplete
disabled="!$ctrl.clientFk || !$ctrl.landed"
disabled="!$ctrl.warehouseFk && (!$ctrl.clientFk || !$ctrl.landed)"
field="$ctrl.warehouseFk"
url="/agency/api/Warehouses"
show-field="name"

View File

@ -14,6 +14,9 @@ class Controller {
$onInit() {
if (this.$stateParams && this.$stateParams.clientFk)
this.clientFk = this.$stateParams.clientFk;
if (window.localStorage && window.localStorage.defaultWarehouseFk)
this.warehouseFk = parseInt(window.localStorage.defaultWarehouseFk);
}
set ticket(value) {
@ -37,6 +40,7 @@ class Controller {
});
} else
this.addressFk = null;
this.getAvailableAgencies();
}
get clientFk() {
@ -45,6 +49,7 @@ class Controller {
set addressFk(value) {
this.ticket.addressFk = value;
this.getAvailableAgencies();
}
get addressFk() {
@ -53,6 +58,7 @@ class Controller {
set landed(value) {
this.ticket.landed = value;
this.getAvailableAgencies();
}
get landed() {
@ -67,10 +73,9 @@ class Controller {
return this.ticket.warehouseFk;
}
getAvailableAgencies() {
this.ticket.agencyModeFk = null;
if (this.ticket.landed && this.ticket.addressFk) {
if (this.ticket.warehouseFk && this.ticket.addressFk && this.ticket.landed && this.ticket.clientFk) {
this.ticket.agencyModeFk = null;
let filter = {warehouseFk: this.ticket.warehouseFk, addressFk: this.ticket.addressFk, landed: this.ticket.landed};
filter = encodeURIComponent(JSON.stringify(filter));
let query = `/api/Agencies/getAgenciesWithWarehouse?filter=${filter}`;

View File

@ -1050,7 +1050,11 @@ INSERT INTO `vn`.`orderTicket`(`orderFk`, `ticketFk`)
(21, 21);
INSERT INTO `vn`.`userConfig` (`userFk`, `warehouseFk`, `companyFk`)
VALUES (9, 1, 442);
VALUES
(1, 2, 69),
(5, 1, 442),
(9, 1, 442),
(18, 3, 791);
INSERT INTO `vn`.`receipt`(`id`, `invoiceFk`, `amountPaid`, `amountUnpaid`, `payed`, `workerFk`, `bankFk`, `clientFk`, `created`, `companyFk`, `isConciliate`)
VALUES