68 lines
1.4 KiB
JavaScript
68 lines
1.4 KiB
JavaScript
import ngModule from '../module';
|
|
import Section from 'salix/components/section';
|
|
import './style.scss';
|
|
|
|
class Controller extends Section {
|
|
$onInit() {
|
|
this.entries = [];
|
|
}
|
|
|
|
get travel() {
|
|
return this._travel;
|
|
}
|
|
|
|
set travel(value) {
|
|
this._travel = value;
|
|
|
|
if (value && value.id) {
|
|
this.getTravel();
|
|
this.getEntries();
|
|
this.getThermographs();
|
|
}
|
|
}
|
|
|
|
getTravel() {
|
|
return this.$http.get(`Travels/${this.travel.id}/getTravel`)
|
|
.then(res => this.travelData = res.data);
|
|
}
|
|
|
|
getEntries() {
|
|
return this.$http.get(`Travels/${this.travel.id}/getEntries`)
|
|
.then(res => this.entries = res.data);
|
|
}
|
|
|
|
getThermographs() {
|
|
const filter = {
|
|
include: {
|
|
relation: 'warehouse',
|
|
scope: {
|
|
fields: ['id', 'name']
|
|
}
|
|
},
|
|
where: {
|
|
travelFk: this.travel.id
|
|
}
|
|
};
|
|
|
|
return this.$http.get(`TravelThermographs`, {filter})
|
|
.then(res => this.travelThermographs = res.data);
|
|
}
|
|
|
|
total(field) {
|
|
let total = 0;
|
|
|
|
for (let entry of this.entries)
|
|
total += entry[field];
|
|
|
|
return total;
|
|
}
|
|
}
|
|
|
|
ngModule.component('vnTravelSummary', {
|
|
template: require('./index.html'),
|
|
controller: Controller,
|
|
bindings: {
|
|
travel: '<'
|
|
}
|
|
});
|