salix/modules/route/front/descriptor/index.js

113 lines
3.1 KiB
JavaScript
Raw Normal View History

2019-03-22 10:07:44 +00:00
import ngModule from '../module';
2020-04-25 09:50:04 +00:00
import Descriptor from 'salix/components/descriptor';
2020-04-25 09:50:04 +00:00
class Controller extends Descriptor {
get route() {
return this.entity;
2019-04-15 12:34:33 +00:00
}
set route(value) {
this.entity = value;
2019-04-15 12:34:33 +00:00
}
showRouteReport() {
2022-09-26 06:07:45 +00:00
this.vnReport.show(`Routes/${this.id}/driver-route-pdf`, {
id: this.id
});
2019-04-15 12:34:33 +00:00
}
sendRouteReport() {
2020-05-22 13:20:55 +00:00
const workerUser = this.route.worker.user;
2022-09-26 06:07:45 +00:00
this.vnEmail.send(`Routes/${this.id}/driver-route-email`, {
2020-05-22 13:20:55 +00:00
recipient: workerUser.emailUser.email,
2022-09-26 06:07:45 +00:00
id: this.id
2020-05-22 13:20:55 +00:00
});
2022-09-13 11:34:32 +00:00
const params = {isOk: true};
return this.$http.patch(`Routes/${this.id}`, params);
2019-04-15 12:34:33 +00:00
}
updateVolume() {
this.$http.post(`Routes/${this.id}/updateVolume`)
.then(() => {
if (this.cardReload) this.cardReload();
this.vnApp.showSuccess(this.$t('Volume updated'));
});
}
2022-11-15 07:24:10 +00:00
deleteCurrentRoute() {
this.$http.delete(`Routes/${this.id}`)
.then(() => {
this.vnApp.showSuccess(this.$t('Route deleted'));
this.$state.go('route.index');
});
}
loadData() {
const filter = {
fields: [
'id',
'workerFk',
'agencyModeFk',
'dated',
'm3',
'warehouseFk',
'description',
'vehicleFk',
'kmStart',
'kmEnd',
'started',
'finished',
'cost',
'zoneFk'
],
include: [
{
relation: 'agencyMode',
scope: {
fields: ['id', 'name']
}
}, {
relation: 'vehicle',
scope: {
fields: ['id', 'm3']
}
}, {
relation: 'zone',
scope: {
fields: ['id', 'name']
}
}, {
relation: 'worker',
scope: {
2023-08-30 10:48:57 +00:00
fields: ['id'],
include: {
relation: 'user',
scope: {
fields: ['id'],
include: {
relation: 'emailUser',
scope: {
fields: ['email']
}
}
}
}
}
}
]
};
return this.getData(`Routes/${this.id}`, {filter})
.then(res => this.entity = res.data);
}
2019-03-22 10:07:44 +00:00
}
2020-04-25 09:50:04 +00:00
ngModule.vnComponent('vnRouteDescriptor', {
2019-03-22 10:07:44 +00:00
template: require('./index.html'),
2020-04-25 09:50:04 +00:00
controller: Controller,
2019-03-22 10:07:44 +00:00
bindings: {
route: '<',
2020-04-25 09:50:04 +00:00
cardReload: '&?'
}
2019-03-22 10:07:44 +00:00
});